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

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 341 ::
收藏到网摘: 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);