2017-08-08 75 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作为函数)以防止内存泄漏也非常重要。

相关问题