如何在 Flash 的外部接口和 JavaScript 之间传递信息?

发布于 2024-07-11 06:59:38 字数 587 浏览 9 评论 0原文

如何使用 flash 中的外部接口将三个参数传递给 java 脚本函数并获取输出并将其显示在 flash 中?


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);
    var output =ExternalInterface.call("calc",int(para[0]),int(para[1]),int(para[2]) );
out.text = output;
}

这是我用来调用函数 calc 的代码,该函数在 java 脚本中接受三个参数,这是正确的方法吗?我如何从 javascript 获取参数并在 flash 中显示它们

How do i pass three arguments using external interface in flash to a java script function and get back output and display it in flash?


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);
    var output =ExternalInterface.call("calc",int(para[0]),int(para[1]),int(para[2]) );
out.text = output;
}

this is the code i am using to call a function calc which takes three arguments in java script, is this the right way of doing it and how can i get arguments back from javascript and display them in flash

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你与昨日 2024-07-18 06:59:38

AS3:

var percent:int = Math.round(100 * done/total);

// pass 3 arguments to javascript
var result:Object = call("progress", { percent:percent, phase:"building", third:"baggage" });

// display what comes back
label.text = "js returned: " + result.status;
if (result.status == "ack")
    continue;
//....

public function call(func:String, args:Object = null):Object
{
   // check to see if we're in a container
   if (ExternalInterface.available)
      return ExternalInterface.call(func, args);
   else
      return { status:"fail" };
}

JavaScript:

<script>
function progress(info)
{
    if (info.phase == "building")
         $("#status").html("Progress: " + info.percent + "% done building");
    //...
    return { status:"ack" };
}
</script>

AS3:

var percent:int = Math.round(100 * done/total);

// pass 3 arguments to javascript
var result:Object = call("progress", { percent:percent, phase:"building", third:"baggage" });

// display what comes back
label.text = "js returned: " + result.status;
if (result.status == "ack")
    continue;
//....

public function call(func:String, args:Object = null):Object
{
   // check to see if we're in a container
   if (ExternalInterface.available)
      return ExternalInterface.call(func, args);
   else
      return { status:"fail" };
}

javascript:

<script>
function progress(info)
{
    if (info.phase == "building")
         $("#status").html("Progress: " + info.percent + "% done building");
    //...
    return { status:"ack" };
}
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文