How To Pass Arguments From Javascript To As3 Using External Interface
I found how to call actionscript from javascript, but I need to pass some arguments too (dynamic),how can I do this? TIA.
Solution 1:
Please, try this:
ExternalInterface.addCallback("sendMsg", generateMsg);
function generateMsg(str):void {
trace(str);
}
JS:
msg = "";
functionsetMsg(myMsg) {
msg = myMsg;
SendDataToFlashMovie(myMsg);
}
Solution 2:
In my experience you have to call the function on the flash object.
I use the following javascript function to get the flash object
functionGetSWF(id) {
if (window.document[id] != null)
if (window.document[id].length == null)
returnwindow.document[id];
elsereturnwindow.document[id][1];
elseif (typeof(document[id]) == 'undefined')
return $('#'+id)[0];
elseif (document[id].length == null)
returndocument[id];
elsereturndocument[id][1];
}
then call the function as follows
var flash = GetSWF('idOfSWF');
if (typeof flash.sendToActionScript === 'function'){
flash.sendToActionScript(yourObject,orParameter);
}
the AS3 would look like follows
if (ExternalInterface.available){
ExternalInterface.addCallback("sendToActionScript",receivedFromJavascript);
}
functionreceivedFromJavascript(myObject:Object,myParameter:String):void{
// Do something
}
Hope this helps.
EDIT:
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];
)
Post a Comment for "How To Pass Arguments From Javascript To As3 Using External Interface"