ExternalInterface.addCallback无法在IE8 Flash 10.0或更低版本中运行

时间:2013-03-06 14:03:07

标签: flash internet-explorer externalinterface

我有一个小的flash应用程序,我在jQuery document.ready上动态加载。它适用于IE以外的所有浏览器。当安装的FlashPlayer版本小于10.1时,通过addCallBack添加的回调不存在。我用flex 3.5中的mxmlc编译了应用程序,目标播放器是9.0.124,所以它应该可以工作。我已经构建了其他更大的flex应用程序,并且没有使用ExternalInterface和IE的问题。应用程序加载和ExternalInterface.call方法触发,IE响应,但回调只是不存在。没有错误被抛出。

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标记

<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>

理想情况下,我不会太担心,但我的老板希望这适用于较旧的Flash版本,因此我们的客户不得不更新。

0 个答案:

没有答案
相关问题