windbreakerdoss / swfobject

Automatically exported from code.google.com/p/swfobject
0 stars 0 forks source link

JS error occurs when embedding an AS3 .swf that has an ExternalInterface callback added to it. #26

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Publish an AS3 .swf that has at least one call to 
ExternalInterface.addCallback(...) in it (which creates an external 
function API for the .swf to be called from Javascript).

2. Use the standard "index_dynamic.html" example code provided in the 
swfobject 2.0rc1 download.

3. Load the web page in a browser.

What is the expected output? What do you see instead?

I expected to see my flash file displayed, and no JS errors to occur.

The alternative content is removed, and my flash file is displayed as 
expected, but then the following JS error is thrown:

Line: 48
Char: 3
Error: Object Required
Code: 0

What version of the product are you using? On what operating system?
I am using swfobject 2.0rc1, Flash 9.0.115.0 player installed, and IE7 
(Win XP SP2).

Please provide any additional information below.
If I remove any calls to ExternalInterface.addCallback(...) from the .swf, 
then no JS error is caused.

Also, I notice that the error occurs even if embedSWF is called AFTER the 
page loads (like in response to a button click), as opposed to inline in 
the HEAD section as the example shows.

And, (this part may not be a bug!) the newly created flash object (which 
replaces the alternative content with the specified id) is NOT given the 
same id as what it replaced, so it's not available to the document.all[] 
accessor.  for instance, after the swf is embedded, a call to document.all
["myContent"] comes back as undefined.

Original issue reported on code.google.com by get...@gmail.com on 29 Dec 2007 at 8:53

GoogleCodeExporter commented 9 years ago
Re: And, (this part may not be a bug!) the newly created flash object (which 
replaces the alternative content with the specified id) is NOT given the 
same id as what it replaced, so it's not available to the document.all[] 
accessor.  for instance, after the swf is embedded, a call to document.all
["myContent"] comes back as undefined.

This is exactly the problem. Your Flash content does entirely replace your HTML
content, including IDs, so that's why your external interface link is broken. 
Just
add the same ID as an attribute to your Flash definition and you will be fine.

A more in depth discussion can be found here:
http://groups.google.com/group/swfobject/browse_thread/thread/6aa4458a4028506/77
a6baa1d3a42cac?lnk=gst&q=bobbyvandersluis#77a6baa1d3a42cac

Original comment by bobbyvandersluis on 2 Jan 2008 at 10:53

GoogleCodeExporter commented 9 years ago
Thank you for pointing me to that forum post.  That is helpful to understand 
exactly 
what it is doing.

However, I'm still not clear on *how* I am supposed to add an ID attribute to 
my 
flash "definition", as you suggest.  I already have the ID on my <div> on my 
container that gets replaced.  

But the embedSWF() function is the one who makes the Flash definition.  Once 
embedSWF
() is done replacing my original <div> (it was able to do so because my div had 
the 
correct id), I no longer have a way via script access the object (by id, for 
instance) to give it an id... i have a chicken-and-the-egg problem.

shouldn't embedSWF() give the new object it creates the same ID as the <div> it 
replaced?  If it's supposed to be doing that, it doesn't appear to be doing so 
in my 
IE7.

Original comment by get...@gmail.com on 2 Jan 2008 at 3:30

GoogleCodeExporter commented 9 years ago
Re: However, I'm still not clear on *how* I am supposed to add an ID attribute 
to my 
flash "definition", as you suggest.

It's all in the documentation, really:
http://code.google.com/p/swfobject/wiki/SWFObject_2_0_documentation

Use something like:

<script type="text/javascript">
var flashvars = {};
var params = {};
var attributes = {
  id: "myContent"
};

swfobject.embedSWF("myContent.swf", "myContent", "300", "120",
"9.0.0","expressInstall.swf", flashvars, params, attributes);
</script>

You can reuse the old id or define an entire new one, in which case you use a
different id for replacement and for internal communication, whatever option 
you prefer.

Re: shouldn't embedSWF() give the new object it creates the same ID as the 
<div> it 
replaced?

No, again if you read
http://groups.google.com/group/swfobject/browse_thread/thread/6aa4458a4028506/77
a6baa1d3a42cac?lnk=gst&q=bobbyvandersluis#77a6baa1d3a
you will know why we chose not to.

Original comment by bobbyvandersluis on 2 Jan 2008 at 5:31