IE 下 用js控制Flash

你看一下这个html文件,用js控制Flash。
<embed id="flashplayer" wmode="Opaque" src="__PUBLIC__/Skins/Sites/default/flash/qy.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="1024" height="300" ></embed>

<script>
	var initFlashNumber=1;
	var flash = document.getElementById("flashplayer");
	
	function initFlashCount(){
	if(flash.IsPlaying() != true){
		if(initFlashNumber==1){
			flash.LoadMovie(1, PUBLIC + "/Skins/Sites/default/flash/znds.swf");
			flash.Play();
			initFlashNumber++;
		}
		else if(initFlashNumber==2){
			flash.LoadMovie(1, PUBLIC + "/Skins/Sites/default/flash/jd.swf");
			flash.Play();
			initFlashNumber++;
		}
		else if(initFlashNumber==3){
			flash.LoadMovie(1, PUBLIC + "/Skins/Sites/default/flash/jdh.swf");
			flash.Play();
			initFlashNumber++;
		}
		else if(initFlashNumber==4){
			flash.LoadMovie(1, PUBLIC + "/Skins/Sites/default/flash/qy.swf");
			flash.Play();
			initFlashNumber=1;
		}
		}
		
	}
    $(document).ready(function(){
	
        $("#search").click(function(){
             var keyword = $("#keyword").val();
             window.location = APP+"/Search/keyword/"+keyword;
        }); 
        var flashInterval=setInterval("initFlashCount()",1000);
				//alert(flash.TotalFrames);
        
		
    });
</script>

1.当前帧=总帧时可以判断为播放完
2.使用IsPlaying()动画是否正在播放 



html:

<HTML><HEAD><TITLE>Flash 播放器</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="Microsoft FrontPage 4.0" name=GENERATOR></HEAD>
<BODY>
<SPAN id=Base></SPAN><BR>
<INPUT οnclick=flash.Zoom(50) type=button value=放大>
<INPUT οnclick=flash.Zoom(200) type=button value=缩小>
<INPUT οnclick=flash.Zoom(0) type=button value=100%>
<INPUT id=Info size=42>
<BR> 
<SCRIPT> 
var Obj,cur,PMax,num,iSize,Chars; 

function ShowFlash(){ 
var f_Url=window.event.srcElement.href;//*
var f_Name=window.event.srcElement.innerText; //* 
PLeft=-Arrow.offsetWidth/2 ; 
Arrow.style.left=PLeft; 
PMax=Arrow.parentElement.offsetWidth-Arrow.offsetWidth-2*PLeft; 
if(f_Url.substr(f_Url.length-4)!=".swf"){alert('错误url');return} 
if(typeof(num)=='number'){ToStop();} 
Base.innerHTML="<object id=flash classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' style='width:300;height:250;display:none'><param name='movie' value="+f_Url+"><param name='quality' value='high'></object>" ; 
num=setInterval("if(flash.readyState!=4){Info.value='Flash加载中,请稍候 … '+flash.PercentLoaded()+'%'};else{flash.style.display='block';clearInterval(num);ToPlay();}",5); 

function MouseDown(){ 
ToStop(1); 
Obj=arguments[0]; 
Obj.setCapture(); 
cur=event.clientX-Arrow.style.pixelLeft; 


function MouseMove(){ 
if(Obj!=null){ 
Obj.style.pixelLeft=(Obj.style.pixelLeft>PMax)?PMax:(Obj.style.pixelLeft<PLeft)?PLeft:event.clientX-cur; 
flash.GotoFrame(parseInt(flash.TotalFrames*(Arrow.style.pixelLeft-PLeft)/PMax)); 
Info.value=flash.CurrentFrame()+'帧 / '+flash.TotalFrames+'帧 = '+parseInt(10000*flash.CurrentFrame()/flash.TotalFrames)/100+'%' ; 


function MouseUp(){ 
if(Obj!=null){ 
ToPlay(); 
Obj.releaseCapture() ; 
Obj=null; 

function ToPlay(){ 
num=setInterval(SetInfo,10); 
flash.Play(); 

function ToStop(){ 
if(typeof num=='number')clearInterval(num); 
if(arguments[0]==null)SetInfo(); 
flash.StopPlay(); 

function SetInfo(){ 
Arrow.style.pixelLeft=flash.CurrentFrame()*PMax/flash.TotalFrames+PLeft; 
Info.value=flash.CurrentFrame()+'帧 / '+flash.TotalFrames+'帧 = '+parseInt(10000*flash.CurrentFrame()/flash.TotalFrames)/100+'%'; 

</SCRIPT>
<SPAN οnmοusedοwn="Arrow.style.pixelLeft=event.offsetX-Arrow.offsetWidth/2;MouseDown(eval('Arrow'));MouseMove();" 
style="BACKGROUND:#000099; WIDTH: 400px; POSITION: relative; HEIGHT:3px">
<SPAN οnmοuseup=MouseUp() οnmοusemοve=MouseMove() 
οnmοusedοwn=MouseDown(this);event.cancelBubble=true; id=Arrow style="LEFT: 0px; WIDTH: 2px; COLOR:#ffffff; POSITION: relative; TOP: 1px; HEIGHT: 1px" 
cur="0">→</SPAN> 
</SPAN>
<br>
<A οnclick="ShowFlash();return false" href="http://flash.qu123.com/newflash/千里共婵娟.swf"
>千里共婵娟</A> 
</BODY>
</HTML>


<!--
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")

--> 

转载于:https://my.oschina.net/tenking/blog/30652

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值