Unload child swf on last frame of child swf

旧街凉风 提交于 2019-12-08 10:19:56

问题


Using AS3 I have in my code a button to stop and remove the swf, but I would like to have in addition to unload a child swf when it plays it's last frame automatically - not using a button.

Here is my code on the main timeline:

var loader:Loader;
var closer:close;

norton_btn.addEventListener(MouseEvent.CLICK, NortonDemo);
function NortonDemo(e:MouseEvent):void 
{
 var req:URLRequest = new URLRequest("norton.swf");
 loader = new Loader();
 loader.load(req);
 container_mc.addChild(loader);
 closer = new close();
 closer.x = 415;
 closer.y = -294;
 addChild(closer);
 closer.addEventListener(MouseEvent.CLICK, closeNortonDemo);

}

function closeNortonDemo(e:MouseEvent):void 
{

 closer.removeEventListener(MouseEvent.CLICK, closeNortonDemo);
 removeChild(closer);
 container_mc.removeChild(loader);
 loader.unloadAndStop();

}

///////////////////////////

Now, what do I need to add or change to this code and add to the code on the last frame of NortonDemo to accomplish what I want to do?

Thanks!


回答1:


you need to delete loaded swf when it plays the last frame?
i'd do it like yhis:

loader.contentLoaderInfo.addEventListener(Event.INIT, onInit);
addChild(loader);
loader.load(new URLRequest("norton.swf"));

private function onInit(e:Event):void {
   (loader.getChildAt(0) as MovieClip).addEventListener(Event.ENTER_FRAME, onFrame);
}

private function onFrame(e:Event):void {
    if((loader.getChildAt(0) as MovieClip).totalFrames == (loader.getChildAt(0) as MovieClip).currentFrame){
        (loader.getChildAt(0) as MovieClip).removeEventListener(Event.ENTER_FRAME, onFrame);//the only thing that might cause a problem imho
         loader.removeChildAt(0);
         loader.unload();
    }
}


来源:https://stackoverflow.com/questions/4115373/unload-child-swf-on-last-frame-of-child-swf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!