Heim  >  Artikel  >  Web-Frontend  >  flash javascript之间的通讯方法小结_javascript技巧

flash javascript之间的通讯方法小结_javascript技巧

WBOY
WBOYOriginal
2016-05-16 18:57:26861Durchsuche
不用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);
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn