Flash frontend issue with Firefox

I'm having a hard time getting ExternalInterface to work in Firefox. I am trying to call an AS3 function from javascript. SWF is configured with correct callbacks and works in IE.

I am using AC_RunActiveContent.js to embed swf into my page. However, I changed it to add the ID to the Object / Embed tags. Following are the object tags and embeds that are generated for IE and 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 a function like this ...

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

      

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

"

Any ideas?

+1


a source to share


7 replies


Hmm, have you specified your ActionScript function to Javascript using addCallback?



Adobe documentation for addCallback

+2


a source


Below is an example of how a Flash movie fits into an html page. This film is a very simple film with great action at the beginning. The movie is shown below in the Test Runs section. This particular html code has been automatically generated by the FlashMX Publish team. Note that the Flash movie file is simplemovie.swf; and the ID and name are automatically assigned by Flash to match the movie file name (minus the .swf extension). In fact, the name and identifier can be anything (but do not use exoteric names, especially do not start with a number), unless it was used by some other element on the same page.

`codebase="http://download.macromedia.com/pub/shockwave/cabs/flash`/swflash.cab#version=6,0,0,0"

 `WIDTH =" 150 "HEIGHT =" 75 "id =" simplemovie "ALIGN =" ">  



 

` quality=medium

 ` swliveconnect = "true" `bgcolor = # FFFFFF WIDTH =" 150 "HEIGHT =" 75 "` name = "simplemovie" `ALIGN = "" `TYPE =" application / x-shockwave-flash "` PLUGINSPAGE = "http://www.macromedia.com/go/getflashplayer">  





there is a play function in flash file that calls this function:

function testEval (stringToEval)
{
  var movie = eval (stringToEval);
  if (movie)
  {
    if (movie.PercentLoaded ())
    {
      if (movie.PercentLoaded () == 100)
      {
        movie.Play ();
      }
      else
      {
        alert ("movie is still loading, try again soon");
      }
    }
    else
    {
      alert ("movie object found-but unable to send command"); 
    }
  }
  else
  {
    alert ("movie object not found");
  }
}
+1


a source


See this post .

You want the JS function to be more like this to get the Flash object (and not getElemById):

function thisMovie(movieName) {
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[movieName];
  } else {
    return document[movieName];
  }
};

      

And don't call this function until the document is loaded.

+1


a source


Try using the same ID in both the object and embed tags . I remember one browser is using one tag and another browser is using another ... not sure which one. I had the same problem a while ago.

I have a modification of the Sample code that comes with flash. Once you've verified that it works, reverse it and adapt it for my use.

In the example, note that the object id tag is set to "ExternalInterfaceExample", then the embed tag has a nameand also the ExternalInterfaceExample parameter. I think this might be your hint.

Good luck!

0


a source


Is your swf visible (on the page) before you try calling them? If not, read the following: swf-not-initializing-until-visible

0


a source


Try these two things:

First try calling a 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);

      

Secondly, I found that calls to ExternalInterface in Firefox only seem to work on inline tags, not object tags. See if you can get it to work if you just use the embed tag. (Right now, I don't know if the posted HTML / Javascript compilation will access the object or the element being inserted.)

0


a source


If instead of using AC_RunActiveContent.js to embed your flash movie you are using swfobject, there is an easy way to do it.

<head>
 <script type="text/javascript" src="swfobject.js"></script>

 <script type="text/javascript">
 try {
      swfobject.getObjectById('jpeg_encoder2').processImage(z); 
      } catch (e) { alert(e.message); }
 </script>
</head>

      

If you are not using swfObject, you can simply copy and paste swfobject.getObjectById right into your code:

<script type="text/javascript">

function getObjectById(objectIdStr) {
        var r = null;
        var o = getElementById(objectIdStr);
        if (o && o.nodeName == "OBJECT") {
            if (typeof o.SetVariable != UNDEF) {
                r = o;
            }
            else {
                var n = o.getElementsByTagName(OBJECT)[0];
                if (n) {
                    r = n;
                }
            }
        }
        return r;

getObjectById('jpeg_encoder2').processImage(z); //call your method 
</script>

      

0


a source







All Articles