1

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

我的应用程序

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>

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

4

0 回答 0