【发布时间】:2011-08-21 02:03:35
【问题描述】:
我首先检查了这个问题: Calling jQuery Function from Flash
如果我们有如下风格的 jQuery 插件:
(function(){
$.fn.pluginName = function () {
var methods = {
init: function ( options ) {
var settings = $.extend( {}, {}, options ); // set your own defaults
$('#flash')[0].initialise(settings);
},
initialised: function ( params ) {
console.log(params);
}
};
var method = 'init', args = [];
if(0 < arguments.length) {
if('object' === typeof(arguments[0])) {
args = arguments;
} else if('undefined' !== typeof(methods[arguments[0])) {
args = Array.prototype.slice.call(arguments);
args.shift();
method = arguments[0];
}
methods[ method ].apply( this, args );
}
return this;
};
})(jQuery);
假设我们用 id="flash" 初始化一个嵌入式 Flash 对象,然后调用:
$('#controller').pluginName('init',{});
并等待 flash 回调。
如果我写了一个函数,例如:
function flashCallBack( data ) {
$('#controller').pluginName('init',data);
}
那么我可以在 AS3 中注册这个函数,但是有没有办法直接在适当的对象上调用插件方法,而不必在全局命名空间中编写上述封装函数?
这不起作用:
ExternalInterface.call("$('#controller').pluginName('initialised',"+data+")");
作为闪存上的函数名称字符串,也不是:
ExternalInterface.call("$('#controller').pluginName('initialised')",data);
任何人都可以为我指出如何直接进行此调用的正确方向或澄清它是否只是不受支持的操作吗?
最诚挚的感谢 :) 自动曝光
【问题讨论】:
标签: jquery flash actionscript-3 externalinterface