9

How do you trigger a javascript function using actionscript in flash?

The goal is to trigger jQuery functionality from a flash movie

2 Answers 2

13

Take a look at the ExternalInterface-Class.
From the AS3-Language Reference:

The ExternalInterface class is the External API, an application programming interface that enables straightforward communication between ActionScript and the Flash Player container– for example, an HTML page with JavaScript. Adobe recommends using ExternalInterface for all JavaScript-ActionScript communication.

And it's work like this:

ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript);
ExternalInterface.call("sendToJavaScript", input.text);

You can submit parameters and recieve callbacks...pretty cool, right? ;)

As I know it will also work on AS2...

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

1 Comment

You probably have a typo since even you're examples show submitting parameters and receiving callbacks
4

As Jochen said ExternalInterface is the way to go and I can confirm that it works with AS2.

If you plan to trigger navigation or anything that affects the area where the flash sits don't do it directly from the function you call from flash. Flash expects a return value from the function it calls and if the flash object does not exist when the function is completed the flash plugin will crash.

If you need to do navigation or alter the content you can add a setTimeout call (into your js function). That will create a new thread and give flash the return value it expects.

Comments

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.