[英]Object oriented Javascript, communication with Flash
I understand that ExternalInterface.call('functionName', arguments);
我了解
ExternalInterface.call('functionName', arguments);
in ActionScript 3 can be used to communicate with Javascript function functionName(arguments)
defined on the HTML page. ActionScript 3中的Java语言可与HTML页面上定义的Javascript
function functionName(arguments)
进行通信。
But what about a custom object instance? 但是自定义对象实例呢? Say that I have:
说我有:
(function (factory, $, undefined) {
factory.worker = function () {
...
};
factory.worker.prototype.init = function (params) {
...
};
factory.worker.prototype.flash_tell_me_something = function (params) {
...
};
}(window.factory = window.factory || {}, jQuery));
And in order to use it, I combine it with jQuery to create an instance, plus the Flash object: 为了使用它,我将其与jQuery结合在一起以创建一个实例以及Flash对象:
$(document).ready(function () {
var myworker = new factory.worker();
myworker.init();
var myloadedcallback = function () {
};
flashVars = {loadedCallback: myloadedcallback};
...
swfobject.embedSWF(swfUrl, id, 215, 138, version, null, flashVars, params);
});
How do I call myworker.flash_tell_me_something(...)
from Flash? 如何从Flash调用
myworker.flash_tell_me_something(...)
?
Try this solution: 试试这个解决方案:
if(ExternalInterface.available)
{
ExternalInterface.call("window.myworker.flash_tell_me_something", "hello");
}
You can also call worker
directly, rather than window.worker
if they are (worker and flash object) in the same namespace. 您也可以直接调用
worker
,而不是window.worker
如果它们在同一命名空间中)(worker和Flash对象)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.