Search code examples
javascriptactionscript-3firefoxexternalinterface

ExternalInterface issue on loadup with FireFox


I have an issue with my ExternalInterface.

The way it is currently set up is, on the page load up, a boolean is set to true in JavaScript and then checked by ActionScript constructors (using a timer) until it is true. This marks that JavaScript is ready to get calls from AS3.

At this point, AS3 will add the callback and do some internal stuff, and at the end of the constructor I call JavaScript. So far so good. JavaScript will at this point call a function in AS3 (that was defined in the callback described above), and this is where it all messes up.

On IE this works perfectly fine. On FireFox though, it does not. When I debug it, I see that the javascript function is called but when it tries to call AS3, nothing happens. I also tried to add a timer, but for some reason the function STILL executes straight away (in IE).

What is very weird is that a second or two later, that function will work, so it seems that the Flash is not completely loaded in FireFox? But it runs to the last line of my constructor, so I would believe it's loaded.

EDIT: I actually did a try/catch, and JavaScript gives me a back a "TypeError: this.version is not a function." The second call to "version" actually works:

Controller.init = function() {
    try {   
        _mainController.getVersion(); // This one does not work
    }
    catch (err) {
        error = err.toString();
    }
}


Controller.addFiles = function(JSON, numberOfFiles) {
    alert(error);

    try {   
        _mainController.getVersion(); // This one works
    }
    catch (err) {
        alert(err.toString()); // This one is never called
    }
}

During init, which is called from the constructor in AS3, it will throw the error, but later on if JavaScript calls getVersion() from addFiles it works (exact same function).

Any idea please, I am really stuck.

Thanks a lot, Rudy


Solution

  • You may have more luck with the Flash Ajax Bridge. It is tuned more into allowing JS to control AS3 files so it may abstract the process of making the connection across different browsers.

    Be aware that plug-in to browser communication is a pain at the best of times.