Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actionscript 3 call a javascript function

is it possible to call javascript functions inside flash (as3)? How about not in the same domain? Can you provide an example snippet for samedomain and not same domain?

thanks!

like image 275
Pennf0lio Avatar asked May 08 '26 02:05

Pennf0lio


1 Answers

Using the ExternalInterface you can communicate with JavaScript from Flash, however only in the window where the Flash application is running.

It is as easy as doing:

ExternalInterface.call("jsFunctionName", argument, argument, ...);

To do the reverse (calling Flash from JavaScript) you do the following first:

ExternalInterface.addCallback("jsFunctionName", callbackFunction);

function callbackFunction(arg:String):void {
    trace(arg);
}

And then you can call jsFunctionName("foo") from JavaScript.

See the adobe docs for more info on that.

As for your cross domain, you can't as far as I know, but you may be able to proxy the call via your server.

like image 126
Seldaek Avatar answered May 09 '26 16:05

Seldaek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!