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

牧云@^-^@ 提交于 2019-12-06 14:39:06
Scott Evernden

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