views:

82

answers:

1

Hello,

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

A: 

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.

James Fassett
I believe this is a race condition between Flash and JavaScript now. Thanks for your answer James. Unfortunately I would rather not use Ajax Bridge if possible. I hope there are other solutions out there, although I have not found anything yet. Thanks.
Rudy
It may still be worthwhile to examine the code in the Ajax Bridge since it is all available open source. You can see how they are solving your issue since it has been tested on the browsers you are targeting.
James Fassett
Oh okay, sorry I did not thought about that. Thanks, I will have a look at how they do it.
Rudy