如何从 Flash 应用程序中调用 JavaScript 函数?

问题描述:

所以在我的 AS 文件中我想调用一个像

So in my AS file I want to call a function like

        public function JS(streamUri:String):void{
        JavascriptCommand(streamUri)
        }

让我的 JS 代码运行...

to get my JS code running...

如何做这样的事情(需要例子)

How to do such thing (Example needed)

听起来您正在寻找 ExternalInterface.call().Adobe 有一篇文章介绍了如何使用它从 ActionScript 调用 JavaScript.

It sounds like you're looking for ExternalInterface.call(). Adobe has an article about how to use it to call JavaScript from ActionScript.

您还可以使用 ExternalInterface 将 ActionScript 公开给 JavaScript,并从 JavaScript 调用 SWF 的内部函数.

You can also use ExternalInterface to expose ActionScript to JavaScript and call functions internal to your SWF from JavaScript.

假设您有一个如下所示的 JavaScript 函数:

Let's say you have a JavaScript function that looks like this:

function specialAlert(msg) {
  alert(msg);
}

从您的 Flash 文件中,您可以像这样调用它:

From your flash file you can call it like this:

import flash.external.*;

ExternalInterface.call("specialAlert", "Hi mom!");

并且您的 JavaScript 函数应该被调用并提醒用户妈妈!".

And your JavaScript function should be called and alert the user "Hi mom!".