首先,您需要监听您的内容何时完成加载 - 因为在此之前您不知道内容有多少帧。
然后,您需要确定何时加载的内容的时间线已完成播放。
下面是一段代码示例,其中包含解释发生了什么的注释。
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