flash javascript之間的通訊方法小結(jié)
更新時間:2008年12月20日 00:15:09 作者:
不用getURL和fsCommand方法個國外的通信方法,值得一看
不用getURL和fsCommand方法
flash使用的actionscript跟javascript是非常相通的,下面描述如何互相調(diào)用函數(shù):
1:javascript調(diào)用flash中的函數(shù)
在flash的腳本中增加
import flash.external.ExternalInterface;
假定要調(diào)用的函數(shù)是hello,as代碼如下
function hello(){
return "hello";
}
ExternalInterface.addCallback("hello", this, hello);
//第一個參數(shù)為導(dǎo)出函數(shù)名,第三個參數(shù)為as的函數(shù)名,這樣就可以在js中調(diào)用as的hello函數(shù)了
2:flash調(diào)用js的函數(shù)
ExternalInterface.call("hello2", "jacky");
//第一個參數(shù)是js的函數(shù)名,后面的是js函數(shù)的參數(shù)
3:如何互相調(diào)用
html代碼如下:
<object type="application/x-shockwave-flash" data="test.swf" width="525" height="390" name="test">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="test.swf" />
<param name="quality" value="high" />
<param name="scale" value="noScale" />
<param name="wmode" value="transparent" />
</object>
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此類函數(shù)取得網(wǎng)頁中的flash對象,只能使用thisMovie函數(shù)中的代碼
國外看到的另一種方法:
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);
flash使用的actionscript跟javascript是非常相通的,下面描述如何互相調(diào)用函數(shù):
1:javascript調(diào)用flash中的函數(shù)
在flash的腳本中增加
import flash.external.ExternalInterface;
假定要調(diào)用的函數(shù)是hello,as代碼如下
function hello(){
return "hello";
}
ExternalInterface.addCallback("hello", this, hello);
//第一個參數(shù)為導(dǎo)出函數(shù)名,第三個參數(shù)為as的函數(shù)名,這樣就可以在js中調(diào)用as的hello函數(shù)了
2:flash調(diào)用js的函數(shù)
ExternalInterface.call("hello2", "jacky");
//第一個參數(shù)是js的函數(shù)名,后面的是js函數(shù)的參數(shù)
3:如何互相調(diào)用
html代碼如下:
<object type="application/x-shockwave-flash" data="test.swf" width="525" height="390" name="test">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="test.swf" />
<param name="quality" value="high" />
<param name="scale" value="noScale" />
<param name="wmode" value="transparent" />
</object>
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此類函數(shù)取得網(wǎng)頁中的flash對象,只能使用thisMovie函數(shù)中的代碼
國外看到的另一種方法:
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);
您可能感興趣的文章:
- javascript檢查瀏覽器是否支持flash的實現(xiàn)代碼
- JavaScript中跨域調(diào)用Flash的方法
- 借助JavaScript腳本判斷瀏覽器Flash Player信息的方法
- javascript檢測瀏覽器flash版本的實現(xiàn)代碼
- JavaScript flash復(fù)制庫類 Zero Clipboard
- Javascript 判斷Flash是否加載完成的代碼
- Javascript+CSS實現(xiàn)Flash動態(tài)新聞效果(pp原創(chuàng))
- Javascript與flash交互通信基礎(chǔ)教程
- 可控制Flash Player的Javascript方法總結(jié)
- javascript獲取flash版本號的方法
相關(guān)文章
JS實現(xiàn)鼠標(biāo)箭頭變成一個燃燒燭光效果的方法
這篇文章主要介紹了JS實現(xiàn)鼠標(biāo)箭頭變成一個燃燒燭光效果的方法,實例分析了javascript操作鼠標(biāo)事件及圖片的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-02-02OpenLayers3實現(xiàn)鼠標(biāo)移動顯示坐標(biāo)
這篇文章主要為大家詳細介紹了OpenLayers3實現(xiàn)鼠標(biāo)移動顯示坐標(biāo),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-09-09