由于没有对我的网页名为myVar的一个全局JavaScript变量,我怎么可以从我的Flash影片使用JavaScript中访问的变量myVar的价值?
Given that there is a global javascript variable on my web page named myVar, how can I access the value of the variable myVar from within my flash movie using javascript?
我看到很多使用外部接口,以便执行从动作的javascript的例子,但我无法找到使用ActionScript回返回值插入Flash影片的例子。
I see plenty of examples of using external interface in order to execute javascript from actionscript, but I am unable to find examples of returning values back into the flash movie using actionscript.
在此先感谢。我希望我的问题是很清楚。
Thanks in advance. I hope my question is clear enough.
ExternalInterface的工作原理是允许JavaScript在电影中调用ActionScript函数,反之亦然。您可以选择接收返回值从调用函数后面。这里有一个很简单的例子:
ExternalInterface works by allowing JavaScript to invoke an ActionScript function in the movie, and vice-versa. You can optionally receive a return value back from the invoked function. Here's a very simple example:
JavaScript的:
JavaScript:
<script language="JavaScript">
function getMyVar()
{
return myVar;
}
</script>
闪存/ AS:
Flash/AS:
import flash.external.ExternalInterface;
var result:string = ExternalInterface.call("getMyVar");