as js communication so easy
action script 《==》javascript
名词解释
通讯:所谓的通讯就是 action script 和 javascript 中的函数可以相互调用,当然不仅限于函数.这里说的是函数;
代码:
flash action script
[javascript]
//加载通讯类
import flash.external.ExternalInterface;
//要在javascript调用的as函数
function hello(t,w){
mytext.text = t;
mytext.width = w;
return 'hello js';
}
//要在javascript调用的as函数必须先被注册
ExternalInterface.addCallback("hello", hello);
//在flash中调用javascript名为test的函数
mybutton.addEventListener(MouseEvent.CLICK,function(){
var te:String = ExternalInterface.call("test",'hehe');
mytext.text = te+'44';
});
[/javascript]
html javascript
[javascript]
//调用as中名为hello的函数
function ok(){
var flashr = document.getElementById("customMenu").hello('testme',100);
console.log(flashr);
}
//要被flash调用的名为test的函数
function test(){
console.log(arguments);
return "fuck";
}
[/javascript]
[html]
<input type="button" value="test" onclick="ok();"/>
[/html]