当前位置: 首页 > 图文教程 > 网络编程 > Javascript > flash javascript之间的通讯方法小结

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

Javascript 中的 flash javascript之间的通讯方法小结


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 387 ::
收藏到网摘: n/a

不用getURL和fsCommand方法个国外的通信方法,值得一看 不用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代码如下:
<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此类函数取得网页中的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);