如何通过外部接口从Javascript传递参数给AS3 [英] how to pass arguments from javascript to as3 using external interface
本文介绍了如何通过外部接口从Javascript传递参数给AS3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现如何从JavaScript调用动作,但我需要传递一些参数太(动态),我该怎么办呢?
I found how to call actionscript from javascript, but I need to pass some arguments too (dynamic),how can I do this?
TIA。
推荐答案
在我的经验,你必须调用Flash对象上的功能。
In my experience you have to call the function on the flash object.
我用下面的JavaScript函数来获取Flash对象
I use the following javascript function to get the flash object
function GetSWF(id) {
if (window.document[id] != null)
if (window.document[id].length == null)
return window.document[id];
else
return window.document[id][1];
else
if (typeof(document[id]) == 'undefined')
return $('#'+id)[0];
else
if (document[id].length == null)
return document[id];
else
return document[id][1];
}
然后调用函数如下:
then call the function as follows
var flash = GetSWF('idOfSWF');
if (typeof flash.sendToActionScript === 'function'){
flash.sendToActionScript(yourObject,orParameter);
}
在AS3看起来像如下
the AS3 would look like follows
if (ExternalInterface.available){
ExternalInterface.addCallback("sendToActionScript",receivedFromJavascript);
}
function receivedFromJavascript(myObject:Object,myParameter:String):void{
// Do something
}
希望这有助于。
Hope this helps.
编辑:
只注意到我在GetSWF功能的小用法的jQuery。我来看看,并尝试删除。 (它的行返回$('#'+ ID)[0];
)
Just noticed that I have a small usage of jQuery in the GetSWF function. I'll take a look and try and remove that. (Its the line return $('#'+id)[0];
)
这篇关于如何通过外部接口从Javascript传递参数给AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文