你如何从闪存中触发javascript函数?

时间:2021-03-21 18:56:00

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

如何在flash中使用actionscript触发javascript函数?

The goal is to trigger jQuery functionality from a flash movie

目标是从flash电影中触发jQuery功能

2 个解决方案

#1


13  

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

看一下ExternalInterface-Class。从AS3语言参考:

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.

ExternalInterface类是外部API,它是一个应用程序编程接口,可以在ActionScript和Flash Player容器之间进行直接通信 - 例如,带有JavaScript的HTML页面。 Adobe建议使用ExternalInterface进行所有JavaScript-ActionScript通信。

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

据我所知,它也适用于AS2 ......

#2


4  

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

正如Jochen所说,ExternalInterface是要走的路,我可以确认它适用于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.

如果您计划触发导航或任何影响闪光灯所在区域的内容,请不要直接从闪光灯调用的功能中进行导航。 Flash期望从它调用的函数返回一个值,如果函数完成时flash对象不存在,flash插件将崩溃。

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.

如果您需要进行导航或更改内容,可以添加setTimeout调用(进入js函数)。这将创建一个新线程并为flash提供它所期望的返回值。

#1


13  

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

看一下ExternalInterface-Class。从AS3语言参考:

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.

ExternalInterface类是外部API,它是一个应用程序编程接口,可以在ActionScript和Flash Player容器之间进行直接通信 - 例如,带有JavaScript的HTML页面。 Adobe建议使用ExternalInterface进行所有JavaScript-ActionScript通信。

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

据我所知,它也适用于AS2 ......

#2


4  

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

正如Jochen所说,ExternalInterface是要走的路,我可以确认它适用于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.

如果您计划触发导航或任何影响闪光灯所在区域的内容,请不要直接从闪光灯调用的功能中进行导航。 Flash期望从它调用的函数返回一个值,如果函数完成时flash对象不存在,flash插件将崩溃。

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.

如果您需要进行导航或更改内容,可以添加setTimeout调用(进入js函数)。这将创建一个新线程并为flash提供它所期望的返回值。