ExternalInterface not working in IE after page refresh

后端 未结 3 1845
梦如初夏
梦如初夏 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.

    0 讨论(0)
  • 2021-02-10 17:46

    There's a bunch of IE bugs w/ ExternalInterface (and flash in general, ime) along different versions. Most recommended fixes suggest using the SwfObject js library, which fixes all the ones I know about. http://www.timelesssky.com/blog/internet-explorer-flash-8-externalinterface-bug

    0 讨论(0)
  • 2021-02-10 17:51

    The issue is that the ExternalInterface class will stop working once the swf file is cached in your browser.

    To overcome this obstacle, you have to modify your html file and your swf files in the following ways: Note: This solution was tested in IE7

    The HTML file - Add parameters to your swf file to make it unique. So the browser will think you need to download a new swf file everytime the page loads.

    For example, if you're using the SWFObject library (which you don't have to), then you would make the following adjustments:

    var cachecontrol = Math.floor(Math.random()*99999);
    var flashvars = {};
    var params = {};
    var attributes = {id:"movie"};
    swfobject.embedSWF("movie.swf?nocache"+cachecontrol, "flashcontent", "100%", "100%", "10.1.0", "expressInstall.swf", flashvars, params, attributes);
    

    As well, add the following meta tag to ensure your html file is not cached:

    The SWF file(s) - If you're loading a swf file from a master swf, then you would have to apply the same logic: var cachecontrol:String = Math.floor(Math.random()*9999).toString(); loader.load(new URLRequest("movie.swf?nocache="+cachecontrol));

    Here is the source of the solution: http://www.emanuelz.com.mx/blog/cache-control-tips-for-flash-120 Note: You don't have to do anymore than what is described above.

    0 讨论(0)
提交回复
热议问题