[SWFObject] Race Condition with Javscript and SWFObject

Aran Rhee aran.rhee at qdc.net.au
Wed Jul 12 17:14:16 PDT 2006


Chris.
 
In the main page, I have this ( I define swfObject first separately to make
sure all functions are available - I think this was the core of your
problem). 
 
<head>
<script language="JavaScript" type="text/javascript"
src="swfobject.js"></script>
<script language="JavaScript" type="text/javascript" src="page.js"></script>
</head>
 
The in the page.js file you can do what you wanted (BTW - you can use single
quotes as the outer string in your write/writeln, so you don't have to
escape all the double quotes inside :) 
 
document.writeln('<body><div id="flashContainer"></div>');
document.writeln('<script type="text/javascript">var so = new
SWFObject("test.swf", "test", "425", "600", "6",
"#ffffff");so.write("flashContainer");<\/script>');
 
 
Also, looks like you are still using an old version of FlashObject, in the
above example, I am using the newer SWFObject.
 
 
Cheers,
Aran
 


  _____  

From: swfobject-bounces at lists.deconcept.com
[mailto:swfobject-bounces at lists.deconcept.com] On Behalf Of Chris Johnson
Sent: Wednesday, 12 July 2006 10:10 AM
To: swfobject at lists.deconcept.com
Subject: [SWFObject] Race Condition with Javscript and SWFObject



Hello there.

 

I have a page (say, page.js) called from a script tag as such:

<script src="page.js"></script>

 

Within page.js, I have something like the following:

document.write("<html><head><script type=\"text/javascript\"
src=\"/flashobject.js\"><\/script></head>");

document.write("<body><div id=\"flashContainer\" ></div>");

document.write("<script type=\"text/javascript\">var flashObject=new
FlashObject(\"test.swf\",\"test\",\"425\",\"600\",\"6\",\"#FFFFFF\");flashOb
ject.write(\"flashContainer\");<\/script></body></html>");

 

 

This works fine in Firefox, but in IE, 50% of the time, I get a message
saying "Error: 'FlashObject' is undefined".  If I add a "defer" attribute to
the script tag, I get the error less frequently.  I am pretty sure this is
caused by a race condition.  I would like to think that the contents of
flashobject.js will be loaded first, preserving sequence, but this does not
appear to be the case.

 

Any suggestions or insights are appreciated.

Thanks,

Chris

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.deconcept.com/pipermail/swfobject-deconcept.com/attachments/20060713/c1c72dde/attachment-0005.htm>


More information about the Swfobject mailing list