外部接口 [英] external interface

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

问题描述

我在java脚本中有一个calc函数,它接受三个整数参数,
以下是AS3代码

  import flash.external.ExternalInterface; 
var para:Array = new Array();
send_btn.addEventListener(MouseEvent.CLICK,clickListener);
函数clickListener(eventObj:Object):void {
para.push(mean.text);
para.push(std.text);
para.push(points.text);
trace(click>+ para);
ExternalInterface.call(calc,para);
}

是这样做的正确方法,如何取回3个参数从javascript中返回并将它们显示在flash中?另外,您需要注册您的AS功能,以使其可用容器:

  ExternalInterface.addCallback(callFlash,myASFunction);然后,从你的容器(JS),你调用AS函数,并传递你想要的任何参数它。 

 < script language =JavaScript> 

flashObject.callFlash(param1,param2,param3);
< / script>

...

< object id =flashObject...>
...
< embed name =flashObject... />
< / object>

最后,在AS3中,编写容器回调时将执行的函数:
$ b $ pre $函数myASFunction(param1:String,param2:String,param3:String):void {
trace(\\ \\ n从JS接收调用:+ param1 + param2 + param3);
}


I have a calc function in java script that takes three integer parameters, following is the AS3 code

import flash.external.ExternalInterface;
var para:Array = new Array();
send_btn.addEventListener(MouseEvent.CLICK, clickListener);
function clickListener(eventObj:Object ):void {
    para.push(mean.text);
    para.push(std.text);
    para.push(points.text);
    trace("click > " + para);
    ExternalInterface.call("calc",para );
}    

is this the right way of doing it and how do i get back 3 arguments back from the javascript and display them in flash?

解决方案

In addition, you need to register your AS function so that it's available to the container:

ExternalInterface.addCallback("callFlash", myASFunction);

Then, from your container (JS), you call the AS function and pass whatever parameters you want to it.

<script language="JavaScript"> 

    flashObject.callFlash(param1, param2, param3); 
</script> 

... 

<object id="flashObject"...> 
    ... 
    <embed name="flashObject".../> 
</object>

Lastly, in AS3, you write the function that will be executed when the container "calls back":

function myASFunction(param1:String,param2:String,param3:String):void {
    trace("\n Received call from JS: " + param1 + param2 + param3);
}

这篇关于外部接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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