一个FLASH与JS结合的例子

      Flash&AS2 2006-1-14 19:2
一个FLASH与JS结合的例子.

下面为HTML文件:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>index</title>
</head>

<body bgcolor="#ffffff" onLoad="index.focus()">

<div style="visibility: hidden;">
<input type="file" name="file" value="" onchange="toFlash(this.value)">
</div>

<!--上面用到一个隐藏域,用于浏览本地的文件的文本框-->

<script language="javascript" src="FsCommand.js"></script>

<!--调入处部的JS文件-->

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"

codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="index" width="600"

height="500" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="sample.swf" />
<param name="quality" value="high" />
<embed src="sample.swf" quality="high" width="600" height="500" swLiveConnect=true id="index" name="index" align="middle"

allowScriptAccess="sameDomain" type="application/x-shockwave-flash"

pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

<!--中间这部份就是FLASH,它里面包含了按钮,我们用它来触发JS事件-->

</body>
</html>

下面为JS文件:
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;


function index_DoFSCommand(command, args) {
var indexObj = isInternetExplorer ? document.all.index : document.index;
switch (command)
{
case "OpenFile" :
file.click ();
}
}
//上面主要是跟FLASH的FSCommand事件联系的;

if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 &&

navigator.userAgent.indexOf("Windows 3.1") == -1) {
document.write('<script language=\"VBScript\"\>\n');
document.write('On Error Resume Next\n');
document.write('Sub index_FSCommand(ByVal command, ByVal args)\n');
document.write(' Call index_DoFSCommand(command, args)\n');
document.write('End Sub\n');
document.write('</script\>\n');
}


function toFlash(value)
{
window.document.index.SetVariable('jsg.Return', value);
}
/*这个是触发FLASH的方法,这边用的很好,用到设置变量,而这个变量是外部类的一个属性;而属性中直接跟内部函数关联,从而产生了触发函数

的作用,以前看到的很多,都是用setInterval来,观察变量是否变化了.那样的方法,浪费资源,又不好理解,在这边,他用的方法就相当聪明了.*/


下面这个类,就是如上讲的类了:
class JSGateway {
function JSGateway() {
}
function set Return(str:String){
_root.upLoadMC(str);
//触发FLASH内部孤upLoadMC()事件;
}
}


下面为FLASH内部的代码:

var jsg:JSGateway = new JSGateway();
//创建JSGateway类;供后面的JS改属性触发下面的事件;

upload_btn.onRelease = function() {
fscommand("OpenFile", "");
};
//这个触发JS的OpenFile事件,你会发现,他会使网页中的隐藏域打开文件框;
function upLoadMC(urls:String) {
var myWin = _root.attachMovie("Win_mc", "Win_mc", 0);
myWin.init("mc", "本地文件", urls);
}
//这个会在JSGateway中的Return属性被改变时触发;

open_btn.onRelease = function() {
var myWin = _root.attachMovie("Win_mc", "Win_mc", 0);
myWin.init("txt", "文本", _root.inoput_txt.text, 400, 300);
};
}
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}