How do you trigger a javascript function using actionscript in flash?
The goal is to trigger jQuery functionality from a flash movie
How do you trigger a javascript function using actionscript in flash?
The goal is to trigger jQuery functionality from a flash movie
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...
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.