[]分享:IDE使用SWF动画的销毁与反复创建

package {
    import laya.events.Event;
    import laya.net.Loader;
    import laya.utils.Handler;
    import view.TestView;
    
    public class LayaUISample {
        
        public function LayaUISample() {
            //初始化引擎
            Laya.init(600, 400);
            start();
        }
        private function start():void
        {
            //加载swf图集资源,只需要加载image.json即可,具体结构请参考附件
            Laya.loader.load([{url: "res/atlas/flicker/image.json", type: Loader.ATLAS}], Handler.create(this, onLoaded));
        }
        private function onLoaded():void {
            //实例UI界面
            var testView:TestView = new TestView();
            testView.mc.play(0,true);
            Laya.stage.addChild(testView);
            Laya.timer.once(2000,this,onLoop,[testView]);
        }
        private function onLoop(testView:TestView):void
        {
            testView.mc.stop();
            testView.mc.destroy();//销毁MC
            testView.removeChildren();
            testView.destroy();
            testView.removeSelf();
            //destroy的时候movieclip把小图都清掉了,但是movieclip不知道你是用图集加载的,图集缓存文件还在,但是图集里的小图已经没有了
            Laya.loader.clearRes("res/atlas/flicker/image.json");//注意:销毁mc时要同时销毁图集的缓存文件
            Laya.stage.on(Event.CLICK,this,onClick);
        }
        private function onClick():void
        {
            start();//重新加载mc动画
        }
    }
}
已邀请:

Monica - 知识达人

赞同来自:

赞,谢谢分享!

要回复问题请先

商务合作
商务合作