ExternalInterface not working in IE after page refresh

后端 未结 3 1844
梦如初夏
梦如初夏 2021-02-10 17:10

I have a bizarre situation in IE where JS can\'t call up into flash using ExternalInterface after I hit \"refresh\". I know the movie is getting loaded and the code that does th

3条回答
  •  醉梦人生
    2021-02-10 17:37

    In case anyone is wondering WHY this happens, at least for Internet Explorer it seems that the Flash player is loaded as an ActiveX control, which is completely seperate from the DOM and JavaScript modules. When the .swf is cached, it seems that the ActiveX control can load and run it before Javascript is ready to accept events from it.

    This means that when Flash tries to use the ExternalInterface to add the callbacks, it will fail because the JavaScript and the DOM have not been loaded.

    I fixed the problem by waiting for the first ENTER_FRAME event, and then registering my callbacks there. Like this:

    protected function registerExternalCallbacks(event:Event):void {
    
        removeEventListener(Event.ENTER_FRAME, registerExternalCallbacks);
    
        if (ExternalInterface.available) {
            ExternalInterface.addCallback("flash_play", play);
            ExternalInterface.addCallback("flash_setVolume", setVolume);
    
            ExternalInterface.call("player_ready");
        }
    }
    
    // and then when the .swf loads, register the function on the event:
    addEventListener(Event.ENTER_FRAME, registerExternalCallbacks);
    

    This will make the player wait until the callbacks can be added reliably, and then calls a javascript function called player_ready to signal that it is ready to be used.

提交回复
热议问题