3

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!

2
  • You mean call javascript functions from flash? I think you should clarify the question, perhaps provide an example or scenario. Commented Jan 13, 2011 at 14:28
  • 1
    There are about ten other questions on the same topic. Try using google or the search field in the top right corner of this page... Commented Jan 13, 2011 at 14:42

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

can we also use to execute some random javascript passed as a string argument to the function ?
No as far as I know it just takes a global function name and calls that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.