How do I pass information between Flash's ExternalInterface and JavaScript?

为君一笑 提交于 2019-12-08 05:48:51

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/435763/how-do-i-pass-information-between-flashs-externalinterface-and-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!