简体   繁体   English

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

[英]How do you trigger javascript functions from flash?

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功能

Take a look at the ExternalInterface -Class. 看一下ExternalInterface -Class。
From the AS3-Language Reference: 从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. ExternalInterface类是外部API,它是一个应用程序编程接口,可以在ActionScript和Flash Player容器之间进行直接通信 - 例如,带有JavaScript的HTML页面。 Adobe recommends using ExternalInterface for all JavaScript-ActionScript communication. 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 ......

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). 如果您需要进行导航或更改内容,可以添加setTimeout调用(进入js函数)。 That will create a new thread and give flash the return value it expects. 这将创建一个新线程并为flash提供它期望的返回值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM