JS判斷Flash是否播放結束


  • 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的指定屬性

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM