我发现如何从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];
)