首先,您需要監聽您的內容何時完成加載 - 因爲在此之前您不知道內容有多少幀。
然後,您需要確定何時加載的內容的時間線已完成播放。
下面是一段代碼示例,其中包含解釋發生了什麼的註釋。
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作爲函數)以防止內存泄漏也非常重要。
這裏的下一個場景意味着主要的.fla文件中的下一個場景 –
你明白了嗎? – BadFeelingAboutThis