2012-12-02 53 views
0

的預加載器我有一個電影嵌入在我的Flash時間軸中,這樣我就可以使用我創建的滾動條框逐幀滾動。不過,由於該電影大約爲10MB,因此我需要在HTML5或Flash中使用某種預加載器來顯示海報圖像,直到電影加載完成。我已經使用預加載器動態加載了影片剪輯,但是如何在影片剪輯嵌入時間軸時執行此操作?我嘗試了一個$(window).ready函數來將海報圖像隱藏在窗口準備就緒,因爲我認爲直到所有資源都加載後纔會觸發,但我認爲這不適用於Flash,所以我想我必須在閃光燈內完成。flash as3&html5 - 當movieclip嵌入時間軸

回答

0

在主影片剪輯(在主時間軸上),您應該添加第一個空幀(它應該是輕量級且加載速度很快)。那麼你應該停止(); MovieClip。停止後,您可以連續檢查loaderInfo.bytesLoaded/loaderInfo.bytesLoaded屬性並顯示加載過程的百分比。

這段代碼可以幫助(你可以把這個代碼放到時間軸的第一幀,或進入主類的構造方法):

//create a text field to show the progress 
var progress_txt:TextField = new TextField(); 
//stop the timeline, will play when fully loaded 
stop(); 
//position text field on the centre of the stage 
progress_txt.x = stage.stageWidth/2; 
progress_txt.y = stage.stageHeight/2; 
addChild(progress_txt); 

//add all the necessary listeners 
loaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress); 
loaderInfo.addEventListener(Event.COMPLETE, onComplete); 


function onProgress(e:ProgressEvent):void 
{ 
    //update text field with the current progress 
    progress_txt.text = String(Math.floor((e.bytesLoaded/e.bytesTotal)*100)); 
} 

function onComplete(e:Event):void 
{ 
    trace("Fully loaded, starting the movie."); 
    //removing unnecessary listeners 
    loaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress); 
    loaderInfo.removeEventListener(Event.COMPLETE, onComplete); 
    //go to the second frame. 
    //You can also add nextFrame or just play() 
    //if you have more than one frame to show (full animation) 
    gotoAndStop(2); 
} 
0

我不知道這是爲什麼不爲我工作..

這裏是我的代碼,在主時間軸:

stop(); 

var percent:Number; //used to show loader progress 

loaderInfo.addEventListener(Event.COMPLETE, onGameLoaded); 
loaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoaderProgress); 
trace(loaderInfo.bytesLoaded, loaderInfo.bytesTotal); 

function onLoaderProgress(event: ProgressEvent): void { 
    trace("Progress called"); 
    percent = (event.bytesLoaded/event.bytesTotal); 
    preloader.bar.scaleX = percent; 
    preloader.percentageTxt.text = String(Math.round(percent * 100)) + "%"; 
} 

//Event-handler for when this main controller is completely loaded 
function onGameLoaded(event: Event): void { 
    loaderInfo.removeEventListener(Event.COMPLETE, onGameLoaded); 
    loaderInfo.removeEventListener(ProgressEvent.PROGRESS, onLoaderProgress); 
    trace("Game completely loaded"); 
    play(); 
} 

的跟蹤語句,甚至沒有射擊,和時間表不會前進。

+0

啊,我發現了這個問題。這僅適用於代碼放置在第一幀的情況。第一幀有一個簡單的「加載」文本框,第二幀有一個簡單的預加載程序。這樣做的原因是,在預加載器欄和資產已加載之前,用戶看不到完全空白的屏幕,但這不起作用。 – Qasim

相關問題