从JavaScript AS3方法调用 [英] AS3 method call from javascript

查看:161
本文介绍了从JavaScript AS3方法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过的SWFObject 当我尝试调用我得到这个错误

I'm trying to call an AS3 function from Javascript via SWFObject when i try calling i get this error

不能叫空的方法'js_method_to_call

import flash.external.ExternalInterface;   
var test_var = ExternalInterface.addCallback("js_method_to_call", moveto);

function moveto() {
gotoAndPlay(1,"Scene 2")

}

而这正是我使用SWFObject的我的HTML文件

and this is my HTML file where i'm using the SWFobject

<head>
        <script type="text/javascript" src="swfobject.js"></script>
        <script type="text/javascript">
            var flashvars = {};
            var params = {};
            var attributes = {};
            attributes.id = "myFlashContent1";
            swfobject.embedSWF("Test_CEO.swf", "containerid", "800", "600", "9.0.0", false, flashvars, params, attributes);
        </script>

        <script type="text/javascript">
        function fall(){
        alert("calling");
        try{
            var myobject = document.getElementById("containerid");
            myobject.js_method_to_call();
        }
        catch(err) {
            alert(err.message);
        }

        }
        </script>
    </head>
    <body>
        <div id="containerid">
            <a href="http://www.adobe.com/go/getflashplayer">
                <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
            </a>
        </div>
         <input id="save file" type="button" value="clickme" onclick="fall();" />
</body>

参考:链接

推荐答案

我通过在运行此解决了这一 XAMPP 服务器

I solved this one by running this on XAMPP server

所以是我重视的SWF文件像这样在我的HTML文件

so yes i attached the swf file like this in my html file

<object id="myMovie" type="application/x-shockwave-flash" data="test.swf" width="550" height="400">
    <param name="movie" value="test.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#ffffff" />
    <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" />
</object>

然后我用锚标记,以将其链接到SWF对象

Then i used the anchor tag to link it to the swf object

<a id="clicky" href="#">click</a>

然后我用这个称之为

Then i called this using this

<script type="text/javascript">
    var clik= document.getElementById("clicky");
    clik.addEventListener("click",function(){
        document.getElementById("myMovie").letsalertme();
    })
</script>

所以当我点击锚标记上的 letsalertme()在SWF文件中的功能将得到执行。

So whenever i click the anchor tag the letsalertme() function inside the swf file will get executed.

这是我的的.fla 文件,其中包含了动作

And this is my .fla file which contains the actionscript

import flash.external.ExternalInterface;

function alertMe():void {
gotoAndPlay(1,"Scene1");
}
ExternalInterface.addCallback("letsalertme",alertMe);

所以,每当我打电话 letsalertme() Javscript 这个函数调用 alertMe 函数,其中 SCENE1 将开始播放。

So whenever i call the letsalertme() from Javscript this function will call the alertMe function where scene1 will start playing.

//编辑:我不使用SWFObject做到了这一点

这篇关于从JavaScript AS3方法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆