您的位置:首页 > Web前端 > JavaScript

flash与js交互ie跟ff通用的方法

2009-05-06 08:29 686 查看

irobot's blog

Home

Archives

Search

Tags

Comments

Tools

ChatHis

Trackbacks

Links

flash与js交互ie跟ff通用的方法

Submitted by irobot on 2009, February 14, 4:36 PM. flash

XML/HTML代码

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"

codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"

width=1 height=1 id="myFlash">

<param name=movie value="src/load.swf">

<param name=quality value=high>

<embed src="src/load.swf" quality=high width=1 height=1 type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" name="myFlash" swLiveConnect="true">

</embed>

</object>

html如上,object是用的id,embed是用的name

JavaScript代码

function thisMovie(movieName) {

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

{

return window[movieName];

} else {

return document[movieName];

}

}

如上方法返回dom对象。

修改赋值flash变量只用thisMovie('myFlash').SetVariable("run", '1');

flash支持的js可调用变量

播放动画:Play()
  例:(网页中的 Flash id).Play();
停止动画:StopPlay()
动画是否正在播放:IsPlaying()
跳转到某帧:GotoFrame(frame_number)
获取动画总帧数:TotalFrames()
回传当前动画所在帧数:CurrentFrame()
使动画返回第一帧:Rewind()
放大指定区域:SetZoomRect(left,top,right,buttom)
改变动画大小:Zoom(percent)
使动画在 x,y 方向上平移:Pan(x_position,y_position,unit)
返回动画被载入的百分比:PercentLoaded()
加载动画:LoadMovie(level_number,path)
例:(网页中的 Flash id).LoadMovie(0, "***/***.swf");
movie_clip 跳转到指定帧数:TGotoFrame(movie_clip,frame_number)
例:(网页中的 Flash id).TGotoFrame("_root.实例名.次实例名",帧数);
movie_clip 跳转到指定标签:TGotoLabel(movie_clip,label_name)
例:(网页中的 Flash id).TGotoLabel("_root.实例名.次实例名","标签名");
回传 movie_clip 当前帧:TCurrentFrame(movie_clip)
回传 movie_clip 当前标签:TCurrentLabel(movie_clip)
播放 movie_clip:TPlay(movie_clip)
停止 movie_clip 的播放:TStopPlay(movie_clip)
获取变量:GetVariable(variable_name)
变量赋值:SetVariable(variable_name,value)
call 指定帧上的 action:TCallFrame(movie_clip,frame_number)
call 指定标签上的 action:TCallLabel(movie_clip,label)
获取 movie_clip 的指定属性:TGetProperty(movie_clip,property)
设置 movie_clip 的指定属性:TSetProperty(movie_clip,property,number)

*反之flash调用js

//导入ExternalInterface类
import flash.external.ExternalInterface;
//下面这个赋值一定要注意,如果是字符串,写法应该是在双引内再加单引,此前我郁闷了一天
var i:String = "’js调用flash中的方法,传递flash变量给js’";
//var i:Number = 1234;
function showAlert(){
//调用js方法jsAlert(),并将flash变量赋值给js
ExternalInterface.call("jsAlert("+i+")");
}
//允许js中的flAlert()调用flash中的showAlert()
ExternalInterface.addCallback("flAlert",null,showAlert);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: