卸载儿童swf最后一帧的儿童swf

时间:2010-11-06 21:56:44

标签: actionscript-3 flash-cs4

使用AS3 我在我的代码中有一个停止和删除swf的按钮,但我想除了卸载子swf时自动播放它的最后一帧 - 使用按钮。

以下是我在主时间轴上的代码:

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

}

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

现在,我需要添加或更改此代码并添加到NortonDemo的最后一帧代码以完成我想要的操作?

谢谢!

1 个答案:

答案 0 :(得分:0)

你需要在播放最后一帧时删除加载的swf吗? 我会像你这样做:

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