Problem accessing ExternalInterface exposed method in Google Chrome Problem accessing ExternalInterface exposed method in Google Chrome google-chrome google-chrome

Problem accessing ExternalInterface exposed method in Google Chrome


I agree with Robson that it is a race condition, but it's not in 'writing the Flash tag' and adding a timer is not a good solution - in fact its very dangerous.

The problem is that the SWF itself isn't loaded and had a chance to initialize your external interface. For a small SWF in Chrome the timing may be more sensitive than other browers, but the underlying problem isn't specific to Chrome.

What you need to do is this :

In Actionscript

Call this function from your constructor :

public function InitializeExternalInterface():void {         if (ExternalInterface.available) {           // register actionscript functions so they can be called by JS              ExternalInterface.addCallback("activate", activate);           Security.allowDomain("www.example.com");                // send message to parent page that SWF is loaded and interface active           trace("External Interface Initialized...");           ExternalInterface.call("flashInitialized")      }      else       {          trace("ERROR: External Interface COULD NOT BE Initialized...");      } }

In your HTML

 <script>     function flashInitialized()      {         alert("Initialized!");      // remove this obviously!         $('#Main')[0].activate();   // safe to call Flash now     } </script>

You may find on your local machine that it works without this, but as soon as you add network delays into the equation you'll regret not doing this. An arbitrary timer is a bad idea because you will still get the error on a slow connection. This method lets the page call the flash object at the earliest possible time.


Note: Using jQuery's 'on ready' pattern is NOT a solution to the problem - although at first I mistook it for one.

$(function() {   $('#animation')[0].SetTitle("Hello"); } 

Also swfobject's callbackFn is also not a solution becasue that just tells you when the tag is inserted and not when the SWF is loaded.


I got the same problem, to fire and recieve listener events between javascript and flash.

The solution was to use AC_OETags.js file from Adobe as embedd script instead of JQuery flash. (It is found in the zip file under Client Side detection, Adobe probably have it some other places as well)

The trouble based on a race condition when the flash builds the javascript callbacks in the browser. This is not handeled correctly by a straight embed for some reason.

<div><script>// Major version of Flash requiredvar requiredMajorVersion = 10;// Minor version of Flash requiredvar requiredMinorVersion = 0;var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);AC_FL_RunContent("src", "tagflash",    "width", "200",    "height", "200",    "id", "myTagFlash",    "quality", "high",    "bgcolor", "#FFFFFF",    "name", "myTagFlash",    "allowScriptAccess","always",    "type", "application/x-shockwave-flash",    "pluginspage", "http://www.adobe.com/go/getflashplayer",    "flashvars", "templateData=theYear:2010&theTagNumber:123");</script></div>

Then you can do: (works in IE, FF, Safari, Crome,++)

$("#tagFlash").gotoNewFrame();


I was having problems with ExternalInterface and Firefox and Chrome and discovered that the Adobe Script was not writing the Flash tag quickly enough, so when the browser tried to find the addCallback() function it was not there at the time.

Simply putting my Javascript function that calls the Flash created addCallback() in a window.setTimeout() calling solves the problem. Delays less than 200 ms still make the problem to occur.

I didn’t have to use the solution of trying to find if the “length” attribute exists in the document[FlashId] object. Just calling “FlashEmbed = document[FlashId]” worked just fine.