js 控制flash 播放 停止 暂停 放大 缩小

转自:http://blog.csdn.net/hingyi/article/details/7691793

 

 

Flash INTERACTION WITH JAVASCRIPT

查看Demohttp://www.iamued.com/demo/flashjs/
重点在于 object的id属性 和 EMBED 的name属性 swliveconnect=”true” 属性

[html] view plain copy
 
  1. <OBJECTclassid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  2. codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
  3. WIDTH="150"HEIGHT="75"id="simplemovie"ALIGN="">
  4. <PARAMNAME=movieVALUE="simplemovie.swf">
  5. <PARAMNAME=qualityVALUE=medium>
  6. <PARAMNAME=bgcolorVALUE=#FFFFFF>
  7. <EMBEDsrc="simplemovie.swf"
  8. quality=medium
  9. swliveconnect="true"
  10. bgcolor=#FFFFFFWIDTH="150"HEIGHT="75"
  11. name="simplemovie"
  12. ALIGN=""
  13. TYPE="application/x-shockwave-flash"
  14. PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
  15. </EMBED>
  16. </OBJECT>

得到JavaScript方法来获取flash对象 兼容多浏览器

[javascript] view plain copy
 
  1. functiongetFlashMovieObject(movieName)
  2. {
  3. if(window.document[movieName])
  4. {
  5. returnwindow.document[movieName];
  6. }
  7. if(navigator.appName.indexOf("MicrosoftInternet")==-1)
  8. {
  9. if(document.embeds&&document.embeds[movieName])
  10. returndocument.embeds[movieName];
  11. }else//if(navigator.appName.indexOf("MicrosoftInternet")!=-1)
  12. {
  13. returndocument.getElementById(movieName);
  14. }
  15. }

  16. function StopFlashMovie()
    {
    var flashMovie=getFlashMovieObject("Myflash");
    flashMovie.StopPlay();
    }


    function PlayFlashMovie()
    {
    var flashMovie=getFlashMovieObject("Myflash");
    flashMovie.Play();
    //embed.nativeProperty.anotherNativeMethod();
    }


    function RewindFlashMovie()
    {
    var flashMovie=getFlashMovieObject("Myflash");
    flashMovie.Rewind();
    }


    function NextFrameFlashMovie()
    {
    var flashMovie=getFlashMovieObject("Myflash");
    // 4 is the index of the property for _currentFrame
    var currentFrame=flashMovie.TGetProperty("/", 4);
    var nextFrame=parseInt(currentFrame);
    if (nextFrame>=9)
    nextFrame=0;
    flashMovie.GotoFrame(nextFrame);
    }




    function ZoominFlashMovie()
    {
    var flashMovie=getFlashMovieObject("Myflash");
    flashMovie.Zoom(90);
    }


    function ZoomoutFlashMovie()
    {
    var flashMovie=getFlashMovieObject("Myflash");
    flashMovie.Zoom(110);
    }




    function SendDataToFlashMovie()
    {
    var flashMovie=getFlashMovieObject("Myflash");
    flashMovie.SetVariable("/:mytext", document.getElementById("data").value);
    }


    function ReceiveDataFromFlashMovie()
    {
    var flashMovie=getFlashMovieObject("Myflash");
    document.getElementById("data").value=flashMovie.GetVariable("/:mytext");
    //document.controller.Data.value=message;
    }

 

js控制flash之参数
引用

Play() ---------------------------------------- 播放动画
StopPlay()------------------------------------停止动画
IsPlaying()----------------------------------- 动画是否正在播放
GotoFrame(frame_number)---------------- 跳转到某帧
TotalFrames()------------------------------- 获取动画总帧数
CurrentFrame()------------------------------回传当前动画所在帧数-1
Rewind()-------------------------------------使动画返回第一帧
SetZoomRect(left,top,right,buttom)-------放大指定区域
Zoom(percent)------------------------------改变动画大小
Pan(x_position,y_position,unit)------------使动画在x,y方向上平移
PercentLoaded()----------------------------返回动画被载入的百分比
LoadMovie(level_number,path)----------- 加载动画
TGotoFrame(movie_clip,frame_number)- movie_clip跳转到指定帧数
TGotoLabel(movie_clip,label_name)------ movie_clip跳转到指定标签
TCurrentFrame(movie_clip)--------------- 回传movie_clip当前帧-1
TCurrentLabel(movie_clip)-----------------回传movie_clip当前标签
TPlay(movie_clip)---------------------------播放movie_clip
TStopPlay(movie_clip)----------------------停止movie_clip的播放
GetVariable(variable_name)-----------------获取变量
SetVariable(variable_name,value)-----------变量赋值
TCallFrame(movie_clip,frame_number)---call指定帧上的action
TCallLabel(movie_clip,label)----------------call指定标签上的action
TGetProperty(movie_clip,property)--------获取movie_clip的指定属性
TSetProperty(movie_clip,property,number)-设置movie_clip的指定属性
其中TGetProperty 和 TSetProperty 的属性是使用数字0-18来获取的,下面是各数字代表的属性:
属性 作用 数字 使用方式

X Position X坐标 0 Get,Set
Y Position Y坐标 1 Get,Set
X Scale X方向缩放比率 2 Get,Set
Y Scale Y方向缩放比率 3 Get,Set
CurrentFrame movie_clip当前所在帧数 4 Get
TotalFrames movie_clip总帧数 5 Get
Alpha movie_clip的透明度 6 Get,Set
Visibility movie_clip是否可见 7 Get,Set
Width movie_clip的宽度 8 Get
Height movie_clip的高度 9 Get
Rotation movie_clip的旋转度 10 Get,Set
Target movie_clip的路径 11 Get
Framesloaded movie_clip已载入的帧数 12 Get
Name movie_clip的实体名字 13 Get,Set
DropTarget movie_clip的拖拽 14 Get
Url 包含movie_clip的动画的url 15 Get
HighQuality 设置画面质量为高质量 16 Get,Set
FocusRect 显示按钮边框 17 Get,Set
SoundBufTime 预设声音缓冲时间 18 Get,Set
flash调用js:
可以使用fscommand来调用js,但使用getUrl方面更为的方便,比如:getURL("BLOCKED SCRIPTalert('"+ message+ "')");就可以使用js的alert的方法作为调试使用.

 


引用

Play() 使已停止了的FLASH动画在停止处开始播放
格式:YourMovieName.Play()
StopPlay() 停止正在播放的FLASH文件?
格式:YourMovieName.StopPlay()
IsPlay() 如果FLASH文件正在播放中,此函数值为true?
例如:if (YourMovieName.IsPlaying)
alert("Playing")
如当动画正在播放,就会弹出一个警告条。
GotoFrame(int frameNum) 控制FLASH跳到指定的frame
格式:YourMovieName.GotoFrame(10)
TotalFrames() 传回FLASH动画的总帧数???
格式:YourMovieName.TotalFrames()
CurrentFrame() 传回FLASH动画目前所在的帧数减一
FS Command控制的帧都是由0开始的
格式:YourMovieName.CurrentFrame()+1
Rewind() 控制FLASH动画条会第一帧并停止?
格式:YourMovieName.Rewind()
SetZoomRect(int left,
int top,int right,int bottom) 放大指定的坐标区域(int left=左坐标的整数;int right为右坐标的整数;int top和int bottom分别表示上坐标和下坐标的整数)

Zoom(int percent) 改变FLASH动画的大小。这函数只允许你将放大后的 图片缩小到原图片的大小
YourMovieName.Zoom(50)放大一倍
YourMovieName.Zoom(200)缩小一倍
YourMovieName.Zoom(0)恢复原始尺寸
Pan(int x,int y,int mode) 平移放大后的FLASH动画。x,y表示移动目的地的x轴和y轴的坐标;int mode表示表示坐标的单位,但其值为"0"时,以象数为单位,为"1"时,以百分比为单位。??

PercentLoaded() 回传0~100的值,此值为浏览器载入FLASH的百分比程度。可用此功能制作loading画面
如:if (YourMovieName.PercentLoaded()$#@60;100)
YourMovieName.GotoFrame(YourMovieName.PercentLoaded())
LoadMovie(int layer,
String url) 载入其他的FLASH动画,"int layer"为level的值,数值越大,动画就放得越上;"string url"为要栽入的动画的路径和名称??
如:LoadMovie(1, "yourmovie.swf")?表示把yourmovie.swf的动画加载到原来的动画上,level为1
LoadMovie("", "yourmovie.swf")表示卸载yourmovie.swf动画?
TGotoFrame(String target,
int frameNum) 控制动画跳到指定的movie clip的第几帧
TGotoFrame("_flash0/mm",10)表示跳到instance name为mm的movie clip的第十帧
TGotoLabel(String target,
String label) 控制动画跳到指定的movie clip的指定的label?
TGotoFrame("_flash0/mm","ten")
TCurrentFrame(String target) 传回指定的movie clip的当前所在帧减一?
fras=YourMovieName.TCurrentFrame("_flash0/mm")+1
TCurrentLabel(String target) 传回指定的movie clip当前所在的label?
label=play_movie.TCurrentLabel("_flash0/mm")
TPlay(String target) 控制指定的movie clip从停止出开始播放
YourMovieName.Play("_flash0/mm")
TStopPlay(String target) 控制指定的movie clip停止播放??
YourMovieName.Play("_flash0/mm")

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值