不用geturl和fscommand方法
flash使用的actionscript跟javascript是非常相通的,下面描述如何互相调用函数:
1:javascript调用flash中的函数
在flash的脚本中增加
import flash.external.externalinterface;
假定要调用的函数是hello,as代码如下
function hello(){
return hello;
}
externalinterface.addcallback(hello, this, hello);
//第一个参数为导出函数名,第三个参数为as的函数名,这样就可以在js中调用as的hello函数了
2:flash调用js的函数
externalinterface.call(hello2, jacky);
//第一个参数是js的函数名,后面的是js函数的参数
3:如何互相调用
html代码如下:
javascript代码如下:
function callfromflash() {
var a=thismovie(test).hello();
alert(a);
}
function thismovie(moviename) {
if (navigator.appname.indexof(microsoft) != -1) {
return window[moviename]
}
else {
return document[moviename]
}
}
//注意,不能使用document.getelementbyid此类函数取得网页中的flash对象,只能使用thismovie函数中的代码
国外看到的另一种方法:
you can't call a function, but you can change/set a variable and use the watch() method to execute the code whenever the value is changed.
actionscript code:
function changetype(prop, oldval, newval) {
//do your stuff
return newval;
}
var strtype = ;
this.watch(strtype, changetype);
