最近新接触Flex,项目里要用到flex与js相互交互,通过flex的ExternalInterface接口的call()很容易实现as调用js方法,但js调as方法却尝试了好久都没有成功,baidu,google半天最后才得其法,今天把它贴出来加深自己记忆,让遇到同样问题的朋友能最快的解决问题:
ExternalInterface
addCallback | () | method |
public static function addCallback(functionName:String, closure:Function):void
Registers an ActionScript method as callable from the container. After a successful invocation of addCallBack()
, the registered function in Flash Player can be called by JavaScript or ActiveX code in the container.
这上面是官方网站上的api说明,我老以为它上面说的functionName是调用as函数的js函数名,怎么调也调不出来。。。
原来addCallback的两个参数:第一个functionName是在js中调用as函数的别名,第二个参数function就是as函数名
ExternalInterface.addCallBack("jsCallback", asFunction);
这样在html 文件中的js就可以能过swfObject.jsCallback()调用asFunction()这个as函数哒。。