external interface

2019-08-31 02:05发布

I have a calc function in java script that takes three integer parameters, following is the AS3 code

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);
    ExternalInterface.call("calc",para );
}    

is this the right way of doing it and how do i get back 3 arguments back from the javascript and display them in flash?

1条回答
Evening l夕情丶
2楼-- · 2019-08-31 02:46

In addition, you need to register your AS function so that it's available to the container:

ExternalInterface.addCallback("callFlash", myASFunction);

Then, from your container (JS), you call the AS function and pass whatever parameters you want to it.

<script language="JavaScript"> 

    flashObject.callFlash(param1, param2, param3); 
</script> 

... 

<object id="flashObject"...> 
    ... 
    <embed name="flashObject".../> 
</object>

Lastly, in AS3, you write the function that will be executed when the container "calls back":

function myASFunction(param1:String,param2:String,param3:String):void {
    trace("\n Received call from JS: " + param1 + param2 + param3);
}
查看更多
登录 后发表回答