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

JS判断Flash是否播放结束

2015-03-30 11:43 323 查看
JS判断Flash是否加载完成

(function () {  var flash = 网页上某个flash对象。
var interval = setInterval(function ()
{

try {  if(flash.IsPlaying()) {

//轮询flash的某个方法即可
callBack && callBack.call(flash, args);
//回调函数  clearInterval(interval);
}
}
catch (ex) {
}  }, 1000);    var callBack = function () {  alert('loaded');  }  })();


具体运用时,flash放进setInterval或者setTimeout的函数闭包中时,可能会由于JavaScript单线程问题,导致flash不能调用IsPlaying等flash player函数或者调用结果不对等状况,这里有个临时的解决办法,我们可以读取在轮询函数中读取flash的TotalFrames属性,读取得到,我们就可以认为flash已经完全加载到页面中了。

JS判断Flash是否播放结束到最后一帧

<script type="text/javascript">

function gotoTestPage(){

//get flash obj, only work normally in IE
var flash = document["Shockwaveflash1"];

//get current page number
var currentFrame=flash.CurrentFrame();

//30 is the total, if end
if(currentFrame==30 && $('#isOpen').html()=="0"){
$('#isOpen').html("1");
alert("Please start to do the test.");

//popup the page with sharepoint dialogue window
OpenPopUpPage("/en/hr/Pages/ISOnlineTest.aspx",function() {window.location.href="/en/hr/Pages/InformationSecurityTraining.aspx";},960,800);
}
}

//go to the function each 5 seconds
setInterval(gotoTestPage,5000);
</script>

//set open popup page status
<div id="isOpen" style="display: none">0</div>


/*后面附上可控制Flash Player的js方法列表*/

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的指定属性
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: