Search code examples
javascriptjquerywordpressactionscript-2externalinterface

ExternalInterface addCallback repeatedly fails


I'm trying to get JS in a Wordpress webpage and an Actionscript 2 Flash movie to talk to one another. The attempt is failing miserably. On every attempt to call the function that I've set a callback for, I get "..... is not a function" in the browser error console (I'm using Firefox 20).

Here's how things are set up:

The page is a bit unusual, being a Wordpress page with inline javascript. The main javascript is a jQuery.ready() block of code that loads the flash object (this is done so that GET parameters in the URL can be passed into the flash). Once it's loaded, there's a link with this:

<a href="javascript:jQuery('#fmap')[0].setRegion('regiona');">Region A</a>

Meanwhile, the flash object has this in it to make it possible:

import flash.external.ExternalInterface;
System.security.allowDomain("thisdomain.com");   // the domain on which the flash is hosted
ExternalInterface.addCallback("setRegion", null, switchZone);  //switchZone is the function's internal name

The flash's container has allowScriptAccess set to "always", and I can confirm that the jQuery statement is hitting the right target. However, when the flash object is debugged, the addCallback returns false— a sign that it's failed. Anyone have any ideas what could be going on?


Solution

  • OK, figured it out. First off, the function declaration needed to be above the ExternalInterface.addCallback bit. In addition, once that was done it started throwing a different error, so I had to make a new function... thanks for your help.