Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ExternalInterface on IE?

Guest
Dec 01, 2009 Dec 01, 2009

Hi, I'm trying to use ExternalInterface to expose functions of my as3 code to javascript. It is working very well, following the Flash CS3 help on Firefox and Chrome browsers, however on IE 8 things are getting hard...

At my HTML page I used the help-suggested functions to confirm the connection between js and as:

<script language="JavaScript" type="text/javascript">
    // variables
    var jsReady = false;    // is javascript ready to listen to flash calls?
    var asReady = false;    // is actionscript ready to receive javascript calls?
   
    // Called when the page is drawn at body tag - at this moment, the JavaScript engine is ready to listen to flash.
    function pageInit() {
        jsReady = true;

        alert('pageinit ok');

    }
   
    // Called by Flash to check wether the JavaScript is ready for communication.
    function isReady() {
        return (jsReady);
        alert ('js ready');
    }


    // Called by flash to inform it is responsive to javascript calls.
    function swfReady() {
        asReady = true;
        alert('swf is ready');
    }

</script>

And, then, I add onload="pageInit()" at the document's body tag. At as3 side, I keep checking for js connection by calling the above functions:

// checking for javascript communcation
private function jsReady():Boolean {
    if (ExternalInterface.available) {
        this._jsOK = ExternalInterface.call("isReady");
        // if javascript is not ready, call this function again at a later time
        if (!this._jsOK) {
            this._jsTimer = new Timer(1000);
            this._jsTimer.addEventListener(TimerEvent.TIMER_COMPLETE, jsLaterCheck);
            this._jsTimer.start();
        } else {
            // set callback functions
            this.setJSCallback();
        }
    }
    return (this._jsOK);
}


// checking again for javascript
private function jsLaterCheck(evt:TimerEvent = null):void {
    this._jsTimer.stop();
    this._jsTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, jsLaterCheck);
    this._jsTimer = null;
    this.jsReady();
}
       
// exposing functions to javascript
private function setJSCallback():void {
    ExternalInterface.call("swfReady");
    ExternalInterface.addCallback("setFlow", jsSetFlow);
}
       
// calling a flow by javascript
public function jsSetFlow(to:String):void {
    // do something
}

At this code, I call jsReady() so it start looking for js connection (retrying if necessary).

When I use this and load the result on Firefox or Chrome everything goies well and the browser shows the alerts. If I try to call the exposed funtion it runs perfectly. However, IE 8 became my nightmare since nothing happens... Just the first alert (page init) is shown, what means that no communication is archived. I confirm this by trying to call the exposed function without success...

I'm embedding the swf file into the html page with Adobe's "AC_FL_RunContent". I add the following params to it: id, name and allowScriptAccess (set to always).

What am I doing wrong? Is there something specific to IE 8 that I must do to expose as3 functions?

Thank you.

TOPICS
ActionScript
687
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2009 Dec 01, 2009

when externalinterface works with some browsers and not others it's almost always because of faulty embedding code.  if you removed any code published by flash, that's a problem.  any code you changed may be a problem.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 01, 2009 Dec 01, 2009

I see... however my embed code is the one automatically generated by dreamweaver. I just add id, name and allowscriptaccess after the first failure...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2009 Dec 01, 2009
LATEST

use the embed code created by flash.  or, at least, test using the embed code generated by flash.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines