JavaScript调用AS3错误

时间:2012-01-26 14:54:13

标签: javascript flash actionscript-3

我正在尝试让我的HTML页面在我的AS3中调用我的函数,但我的JavaScript一直在说not a function。我的SWF在同一个域中。

AS3:

public function Client() {
        ExternalInterface.call('flashReady');
        if (ExternalInterface.available) {
            //ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript);
            ExternalInterface.addCallback("jsPlayStream", onPlayStreamHandler); //FLV.play()
            ExternalInterface.addCallback("jsStopStream", onStopStreamHandler); //FLV.stop()
            ExternalInterface.addCallback("jsSoundStream", onSoundHandler); ////FLV.volume(0 - 1)
        }
}

private function onPlayStreamHandler(value:String):void {
    flvPlayer.play();
}

private function onStopStreamHandler(value:String):void {
    flvPlayer.stop();
}

private function onSoundHandler(value:Boolean):void {
    if (value == true) {
        flvPlayer.volume = 1;
    } else {
        flvPlayer.volume = 0;
    }
}

JS代码:

$("#vidPlay").click(function () {
    if (bFlashReady == true) {
        thisMovie("Client").jsPlayStream("play");
     }
});

$("#vidPause").click(function () {
    if (bFlashReady == true) {
        thisMovie("Client").jsStopStream("stop");
    }
});

$("#vidSoundOn").click(function () {
    if (bFlashReady == true) {
        thisMovie("Client").jsSoundStream(true);
    }
});

$("#vidSoundOff").click(function () {
    if (bFlashReady == true) {
        thisMovie("Client").jsSoundStream(false);
    }
});

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}

HTML:

           <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="222" height="174" id="Client" align="middle">
                <param name="movie" value="Client.swf?v=1.1" />
                <param name="quality" value="high" />
                <param name="bgcolor" value="#2B2B2B" />
                <param name="play" value="true" />
                <param name="loop" value="true" />
                <param name="wmode" value="window" />
                <param name="scale" value="showall" />
                <param name="menu" value="true" />
                <param name="devicefont" value="false" />
                <param name="salign" value="" />
                <param name="allowScriptAccess" value="always" />
                <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="Client.swf" width="222" height="174">
                    <param name="movie" value="Client.swf?v=1.1" />
                    <param name="quality" value="high" />
                    <param name="bgcolor" value="#2B2B2B" />
                    <param name="play" value="true" />
                    <param name="loop" value="true" />
                    <param name="wmode" value="window" />
                    <param name="scale" value="showall" />
                    <param name="menu" value="true" />
                    <param name="devicefont" value="false" />
                    <param name="salign" value="" />
                    <param name="allowScriptAccess" value="always" />
                <!--<![endif]-->
                    <a href="http://www.adobe.com/go/getflash">
                        <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                    </a>
                <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
            </object>

1 个答案:

答案 0 :(得分:2)

我认为找到Flash对象的代码可以通过使用document.getElementById()来简化(并且可能已修复)。

function thisMovie( movieName ) {
    return document.getElementById( movieName );
}