|
官方文檔:
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);});
第二個參數隨便填都行
|