如何用flash / actionscript 3调用javascript函数

时间:2009-08-31 09:39:52

标签: javascript flash actionscript-3

我想通过动作脚本3从我的flash菜单调用我的update(id) javascript函数。我该怎么办?

2 个答案:

答案 0 :(得分:2)

您可以使用ExternalInterface.call。

import flash.external.ExternalInterface;


ExternalInterface.call('update', id);

答案 1 :(得分:0)

<script>
function displayCurrentTime()
{
var date = new Date();
return date.toLocaleTimeString();
}
</script>

您可以像往常一样调用此函数,但只需将其调用为任何其他类型的getter函数,其中将返回值存储为某个变量的一部分:

var currentTime:string = ExternalInterface.call("displayCurrentTime()");

当此代码运行时,Flash将调用displayCurrentTime JavaScript函数并将其返回的值存储在currentTime变量中。