gpt4 book ai didi

javascript - 如何在 Flash 的 ExternalInterface 和 JavaScript 之间传递信息?

转载 作者:行者123 更新时间:2023-11-30 13:44:02 24 4
gpt4 key购买 nike

我如何使用 Flash 中的外部接口(interface)将三个参数传递给 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 中显示它们

最佳答案

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>

关于javascript - 如何在 Flash 的 ExternalInterface 和 JavaScript 之间传递信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/435763/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com