Sinnbeck
Sinnbeck

Reputation: 667

ExternalInterface.addCallback with 2 arguments

I am trying to pass 2 variables from javascript to flash. I figured I could do something like this i as3 to try and recieve them.

ExternalInterface.addCallback("callAs", muscle, tension);

Sadly this throws an error

1137: Incorrect number of arguments. Expected no more than 2.

Is there a way to send 2 variables instead of having to make 2 calls each time?

Thanks in advance! Resin

Upvotes: 0

Views: 5189

Answers (1)

crooksy88
crooksy88

Reputation: 3851

It is possible.

ExternalInterface.addCallback("theFunctionNameInJavascript", theFunctionNameInActionscript);

function theFunctionNameInActionscript(param1:String, param2:String):void {
//do something with param1;
//do something with param2;

}

Then in Javascript you would have something like...

<!-- work out if we are on Mac or PC -->
function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}

function theFunctionNameInJavascript(swf, param1, param2) {
    getFlashMovie(swf).theFunctionNameInActionscript(param1, param2);
}

And you would trigger this with something like...

<form action="javascript:theFunctionNameInJavascript('idNameOfYourSWF', 'thisisparam1', 'thisIsParam2')" id="form">
<input type="submit" value="Click Me" />
</form>

Upvotes: 7

Related Questions