ExternalInterface.addCallback not working in IE8 Flash 10.0 or below

天涯浪子 提交于 2019-12-11 08:58:05

问题


I have a small flash app that I load dynamically upon jQuery document.ready. It works in all browsers except for IE. When the installed version of FlashPlayer is less than 10.1, the callbacks added via addCallBack are not present. I've compiled the app with the mxmlc in flex 3.5 which the target player is 9.0.124 so it should work. I've built other larger flex apps and had no problems with ExternalInterface and IE. The app loads and the ExternalInterface.call method fires and IE responds, but the callbacks just aren't there. No errors are being thrown.

MyApp.as

public class MyApp extends Sprite {
    private var sounds:Dictionary = new Dictionary();
    private var channel:SoundChannel = new SoundChannel();
    private var onLoadHandler:String;

    public function MyApp() {
        flash.system.Security.allowDomain("*");

        var flashvars:Object = LoaderInfo(this.root.loaderInfo).parameters;
        onLoadHandler = flashvars.onLoad;

        addEventListener(Event.ENTER_FRAME, registerExternalCallbacks);
     }

    private function registerExternalCallbacks(event:Event):void{
        removeEventListener(Event.ENTER_FRAME, registerExternalCallbacks);

        if (ExternalInterface.available) {
            ExternalInterface.addCallback("addSound", addSound);
            ExternalInterface.addCallback("playSound", playSound);
            ExternalInterface.addCallback("getCameraCount", getCameraCount);

            if (onLoadHandler) {
                ExternalInterface.call(onLoadHandler);
            }
        }
    };

    private function addSound(name:String, url:String):void{
        var sound:Sound = new Sound();
        sound.load(new URLRequest(url));
        sounds[name] = sound;
    }

    private function playSound(name:String):void{
        if (sounds[name] != null) {
             channel = sounds[name].play();
        }
    }

    private function getCameraCount():int {
        return Camera.names.length;
    }
}

HTML markup

<object width="1" height="1" id="MyApp" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" style="position: absolute; top: -999px; left: -999px;">
    <param value="MyApp.swf" name="movie">
    <param value="always" name="allowScriptAccess">
    <param value="false" name="allowFullScreen">
    <param value="false" name="loop">
    <param value="false" name="menu">
    <param value="high" name="quality">
    <param value="onLoad=onLoad" name="flashvars">
    <embed width="1" height="1" flashvars="onLoad=onLoad" quality="high" menu="false" loop="false" allowfullscreen="false" allowscriptaccess="always" name="MyApp" src="MyApp.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" swliveconnect="true" type="application/x-shockwave-flash">
</object>

Ideally, I wouldn't be too worried, but my boss would like this to work for older flash versions so our customers are forced to update.

来源:https://stackoverflow.com/questions/15249351/externalinterface-addcallback-not-working-in-ie8-flash-10-0-or-below

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!