2017-08-08 72 views
2

我目前正在使用adobe flash cc 2014,並且我已經加載了一個包含大約5000幀動畫的.swf文件。然後我想在加載的文件完成播放後進入下一個場景。如何在裝載swf後在As3 Flash中播放下一場景cc

這是代碼我有,只是簡單的裝載代碼:

stop(); 
var myLoader:Loader = new Loader(); 
var url:URLRequest = new URLRequest("jenissendi.swf"); 
myLoader.load(url); 
addChild(myLoader); 

現在,我應該做這個代碼? 有人可以給我一個簡單的步驟,因爲我仍然是新手在這裏

謝謝。

+0

這裏的下一個場景意味着主要的.fla文件中的下一個場景 –

+0

你明白了嗎? – BadFeelingAboutThis

回答

0

事情大約裝載機類,它可以混淆初學者的事件,相關的加載過程中,從連接到裝載機而不是裝載機本身的LoaderInfo對象調度。

stop(); 

var myLoader:Loader = new Loader; 
var url:URLRequest = new URLRequest("jenissendi.swf"); 

myLoader.contentLoaderInfo.addEventListener(Event.INIT, onInit); 
myLoader.load(url); 

addChild(myLoader); 

function onInit(e:Event):void 
{ 
    nextScene(); 
} 
0

首先,您需要監聽您的內容何時完成加載 - 因爲在此之前您不知道內容有多少幀。

然後,您需要確定何時加載的內容的時間線已完成播放。

下面是一段代碼示例,其中包含解釋發生了什麼的註釋。

stop(); 
var myLoader:Loader = new Loader(); 
var url:URLRequest = new URLRequest("jenissendi.swf"); 

//before you load, listen for the complete event on the contentLoaderInfo object of your loader 
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, contentLoaded, false, 0, true); 

myLoader.load(url); 
addChild(myLoader); 

//this function runs when the content is fully loaded 
function contentLoaded(e:Event):void { 
    var loadedSwf:MovieClip = myLoader.content as MovieClip; //this is the main timeline of the loaded content 
    loadedSwf.addFrameScript(loadedSwf.totalFrames - 1, contentFinished); 
    //the line above tells the movie clip to run the function 'contentFinished' when it reaches the last frame. 
} 

//this function runs when the loaded content reaches it's last frame 
function contentFinished():void { 
    //clean up to avoid memory leaks 
    removeChild(myLoader); 
    loadedSwf.addFrameScript(loadedSwf.totalFrames - 1, null); 

    nextScene(); 
} 

addFrameScript有一些細微差別。首先,它讀取幀數爲0。這意味着第一幀是第0幀。這就是爲什麼你從總幀中減去1來得到最後一幀。其次,addFrameScript是一個未公開的功能 - 這意味着它可能在某些未來的Flash播放器/ AIR版本不再起作用 - 儘管在這一點上這是不太可能的。 刪除幀腳本(通過傳遞null作爲函數)以防止內存泄漏也非常重要。

相關問題