开发者

Unload child swf on last frame of child swf

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开发者_StackOverflow to the code on the last frame of NortonDemo to accomplish what I want to do?

Thanks!


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();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜