views:

1720

answers:

4

I am having a hard time getting ExternalInterface to work on Firefox. I am trying to call a AS3 function from javascript. The SWF is setup with the right callbacks and it is working in IE.

I am using AC_RunActiveContent.js to embed the swf into my page. However, I have modified it to add an ID to the Object / Embed Tags. Below are object and embed tag that are generated for IE and for Firefox respectively.

    <object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="400" height="400" align="middle" id="jpeg_encoder2" name="jpeg_encoder3" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" >
    <param name="movie" value="/jpeg_encoder/jpeg_encoder3.swf" /> 
    <param name="quality" value="high" /> 
    <param name="play" value="true" /> 
    <param name="loop" value="true" /> 
    <param name="scale" value="showall" /> 
    <param name="wmode" value="window" /> 
    <param name="devicefont" value="false" /> 
    <param name="bgcolor" value="#ffffff" /> 
    <param name="menu" value="false" /> 
    <param name="allowFullScreen" value="false" /> 
    <param name="allowScriptAccess" value="always" /> 
</object>


<embed 
    width="400" 
    height="400" 
    src="/jpeg_encoder/jpeg_encoder3.swf" 
    quality="high" 
    pluginspage="http://www.macromedia.com/go/getflashplayer" 
    align="middle" 
    play="true" 
    loop="true" 
    scale="showall" 
    wmode="window" 
    devicefont="false" 
    id="jpeg_encoder2" 
    bgcolor="#ffffff" 
    name="jpeg_encoder3" 
    menu="false" 
    allowFullScreen="false" 
    allowScriptAccess="always" 
    type="application/x-shockwave-flash" > 
</embed>

I am calling the function like this...

<script>
try {
    document.getElementById('jpeg_encoder2').processImage(z);
} catch (e) { alert(e.message); }
</script>

In Firefox, I get an error saying "document.getElementById("jpeg_encoder2").processImage is not a function"

Any Ideas?

A: 

Try having the same id in both object and embed tags. I remember one browser is using one tag and another browser the other...don't know which one is which. I had the same issue some time ago.

I'm got around by modifying the Example Code that comes with flash. Making sure it works, then stripping it down and adapting it for my use.

In the example notice that the object tag the id set to "ExternalInterfaceExample", then the embed tag has the name parameter set to "ExternalInterfaceExample" as well. I think that might be your clue.

Good luck!

George Profenza
+1  A: 

Hmm, did you expose your actionscript function to Javascript with addCallback ?

Adobe documentation on addCallback

SleepyCod
A: 

Are your swf's visible (on the page) before you try calling them? If not, read this: swf-not-initializing-until-visible

Jason
A: 

Try these two things:

First, try calling the function from Javascript like this:

var swf;
if(navigator.appName.indexOf("Microsoft") != -1) {
    swf = window["jpeg_encoder2"];
} else {
    swf = document["jpeg_encoder2"];
}
if(typeof(swf) == "undefined") swf = document.getElementById("jpeg_encoder2");

swf.processImage(z);

Second, I've found that ExternalInterface calls in Firefox seem to only work with embed tags, not object tags. See if you can get it to work if you just use an embed tag. (Right now, I'm not clear whether the HTML/Javascript combo you've posted will access the object or the embed element.)

Sean