Prakash Raman
Prakash Raman

Reputation: 13943

Call an ActionScript function from Javascript

I want to call an Action Script function from javascript. But also I need the ActionScript function to return a value to the javascript call.

This is what I want to accomplish.

 /* JS CODE */

 var str = getStringFromFlash();
 alert(str);

getStringFromFlash should be a function defined in ActionScript that can return a value.

Upvotes: 1

Views: 2138

Answers (2)

Manish
Manish

Reputation: 3522

On the Flash side:

ExternalInterface.addCallback("getValue", getValue);

Where getValue() is the function that returns the string.

Then on the JavaScript side:

var flashObject = document.getElementById("myFlashObject");
var str = flashObject.getValue();
alert(str);

See API documentation for the ExternalInterface class for a more complete example.

Upvotes: 5

www0z0k
www0z0k

Reputation: 4434

ExternalInterface.addCallback()

Upvotes: 1

Related Questions