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:

Read More

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?

Related posts

Leave a Reply

2 comments

  1. I met this kind of problem before. To explain this, you may just image your flash file to be a image. Usually, the image in you page will show after the whole page is loaded. For your flash file, in $.ready event, the flash DOM is inserted into your page, but the content of it is loading and the environment of it is not ready yet.

    To handle this, you need to register a callback function in your page like this:

    window.ping = function () {
        $('#fmap')[0].setRegion('regiona');
    }
    

    Then in your flash environment, call the ping() registered.

    The order of function call is the key point here.

  2. 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.