1

如何使用 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 中显示它们

4

1 回答 1

3

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>
于 2009-01-12T16:24:36.650 回答