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)文章
非常漂亮的讓背景如此暗淡(一種彈出提示信息時頁面背景色調(diào)改變的方法)
非常漂亮的讓背景如此暗淡(一種彈出提示信息時頁面背景色調(diào)改變的方法)...2007-04-04
詳解微信小程序(Taro)手動埋點和自動埋點的實現(xiàn)
這篇文章主要介紹了詳解微信小程序(Taro)手動埋點和自動埋點的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03
Bootstrap中g(shù)lyphicons-halflings-regular.woff字體報404錯notfound的解
這篇文章主要介紹了 Bootstrap中g(shù)lyphicons-halflings-regular.woff字體報404錯notfound的解決方法,需要的朋友可以參考下2017-01-01
JS動態(tài)解析多層級json數(shù)據(jù)生成html頁面
在Web前端開發(fā)中,動態(tài)解析JSON數(shù)據(jù)并生成HTML頁面是一項常見的任務(wù),通過JavaScript處理多層級的JSON數(shù)據(jù)結(jié)構(gòu),不僅可以提升用戶體驗,還能實現(xiàn)靈活的內(nèi)容展示和交互功能,本文將深入探討如何使用JavaScript解析復(fù)雜的JSON數(shù)據(jù),并將其動態(tài)渲染為HTML頁面2025-02-02
JavaScript實現(xiàn)為圖片添加水印的方法詳解
在很多地方,我們都可以看到,上傳圖片的時候,圖片都會被加上默認的水印,因此,我們在個人網(wǎng)站進行圖片操作時,也可以給它加上自己獨特的水印,本文就為大家整理了JS添加圖片合文字水印的方法,需要的可以參考一下2023-05-05

