How do you trigger javascript functions from flash

2019-01-24 08:55发布

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

The goal is to trigger jQuery functionality from a flash movie

2条回答
女痞
2楼-- · 2019-01-24 09:10

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...

查看更多
爷、活的狠高调
3楼-- · 2019-01-24 09:16

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.

查看更多
登录 后发表回答