js怎么判斷flash swf文件是否加載完畢

字號(hào):


    js怎么判斷flash是否加載完畢了呢?
    我們怎么在flash加載完畢之時(shí),回調(diào)一個(gè)我們設(shè)定的js函數(shù)?
    這個(gè)問題,一直困擾了我很久,直到今天,請(qǐng)教了一個(gè)非常牛B的人物之后,突然來了感覺!
    呵呵,也許,這個(gè)問題在你們看來不是問題,不過對(duì)于我來說,確實(shí)是個(gè)問題,因?yàn)槲乙恢辈恢涝撛趺磁袛鄐wf文件是否加載完畢了?
    從前都是只知道img.onload等等。
    好了,言歸正傳,我們到底該怎樣判斷一個(gè)flash是否加載完了呢?
    沒錯(cuò),就是輪詢,然后判斷flash的某個(gè)方法是否能正常運(yùn)行?
    示例如下(偽代碼):
    view sourceprint?
    01 (function () {
    02 var flash = 網(wǎng)頁上某個(gè)flash對(duì)象。
    03
    04 var interval = setInterval(function () {
    05 try {
    06 if(flash.IsPlaying()) { //輪詢flash的某個(gè)方法即可
    07 callBack && callBack.call(flash, args); //回調(diào)函數(shù)
    08 clearInterval(interval);
    09 }
    10 } catch (ex) {
    11
    12 }
    13 }, 1000);
    14
    15 var callBack = function () {
    16 alert('loaded');
    17 }
    18 })();
    //具體運(yùn)用時(shí),flash放進(jìn)setInterval或者setTimeout的函數(shù)閉包中時(shí),可能會(huì)由于JavaScript單線程問題,導(dǎo)致flash不能調(diào)用IsPlaying等flash player函數(shù)或者調(diào)用結(jié)果不對(duì)等狀況,這里有個(gè)臨時(shí)的解決辦法,我們可以讀取在輪詢函數(shù)中讀取flash的TotalFrames屬性,讀取得到,我們就可以認(rèn)為flash已經(jīng)完全加載到頁面中了?。?!
    經(jīng)測試,確實(shí)可行,不過可能會(huì)有1—2秒的時(shí)間延遲。
    /////////////有什么不對(duì)的地方,歡迎勘誤?。。。。。。。?!//////////////
    /*后面附上可控制Flash Player的js方法列表*/
    Play() ---------------------------------------- 播放動(dòng)畫
    StopPlay()------------------------------------停止動(dòng)畫
    IsPlaying()----------------------------------- 動(dòng)畫是否正在播放
    GotoFrame(frame_number)---------------- 跳轉(zhuǎn)到某幀
    TotalFrames()------------------------------- 獲取動(dòng)畫總幀數(shù)
    CurrentFrame()------------------------------回傳當(dāng)前動(dòng)畫所在幀數(shù)-1
    Rewind()-------------------------------------使動(dòng)畫返回第一幀
    SetZoomRect(left,top,right,buttom)-------放大指定區(qū)域
    Zoom(percent)------------------------------改變動(dòng)畫大小
    Pan(x_position,y_position,unit)------------使動(dòng)畫在x,y方向上平移
    PercentLoaded()----------------------------返回動(dòng)畫被載入的百分比
    LoadMovie(level_number,path)----------- 加載動(dòng)畫
    TGotoFrame(movie_clip,frame_number)- movie_clip跳轉(zhuǎn)到指定幀數(shù)
    TGotoLabel(movie_clip,label_name)------ movie_clip跳轉(zhuǎn)到指定標(biāo)簽
    TCurrentFrame(movie_clip)--------------- 回傳movie_clip當(dāng)前幀-1
    TCurrentLabel(movie_clip)-----------------回傳movie_clip當(dāng)前標(biāo)簽
    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指定標(biāo)簽上的action
    TGetProperty(movie_clip,property)--------獲取movie_clip的指定屬性
    TSetProperty(movie_clip,property,number)-設(shè)置movie_clip的指定屬性