官方文档:
addCallback(ExternalInterface.addCallback 方法)
public static addCallback(methodName:String, instance:Object, method:Function) : Boolean
将 ActionScript 方法注册为可从容器调用。成功调用 addCallBack() 后,容器中的 JavaScript 或 ActiveX 代码可以调用在 Flash Player 中注册的函数。
可用性:ActionScript 1.0;Flash Player 8
参数
methodName:String - 从 JavaScript 调用 ActionScript 函数时可使用的名称。此名称不必与 ActionScript 方法的实际名称匹配。
instance:Object - this 在该方法中被解析成的对象。此对象不一定是在其上可找到该方法的对象,您可以指定任何对象(或 null )。 instance:Object - The object to which this resolves in the method. This object is not necessarily the object on which the method can be found -- you can specify any object (or null ). method:Function - 要从 JavaScript 调用的 ActionScript 方法。
在instance的说明里“该方法”其实指的是参数method。 就是说在method里的this指代的是instance,也可以在method里直接“instance.function”这样来调用
所以instance就是个可有可无的参数
例子:
ExternalInterface.addCallback(‘callFlash‘, a, function(t:String){this.s(t);});
这里js调用callFlash就是调用a.s
也可以直接调用a.s:
ExternalInterface.addCallback(‘callFlash‘, null, function(t:String){a.s(t);});
第二个参数随便填都行
|