本文介绍了当外部SWF已达到帧x,我怎么卸载呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的swf装载code:

Here's my swf loading code:

function loadBall(e:MouseEvent):void{
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("ball.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}

function onCompleteHandler(loadEvent:Event){
    currentMovie = MovieClip(loadEvent.currentTarget.content) 
    addChild(currentMovie);
    trace(loadEvent);
}
function onProgressHandler(mProgress:ProgressEvent){
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}

我要检测是否ball.swf已经达到244架,然后卸载它。有没有办法做到这一点,而不下载其它类?

I wish to detect if ball.swf has reached frame 244 and then unload it. Is there a way to do this without downloading additional classes?

推荐答案

在球影片剪辑的帧244,你可以派遣一个事件通知MainTimeline那架244已经到达,那么你将需要删除的所有引用球MC,让在那里的垃圾收集处理。

In frame 244 of the ball movie clip, you could dispatch an event to inform the MainTimeline that frame 244 has been reached, then you will need to delete all references to the ball mc and let garbage collection handle it from there.


//in the ball movie clip, on frame 244

this.dispatchEvent( new Event("End of Movie") );

//in the main timeline , after loading the swf

function onCompleteHandler(event:Event):void
{
   //keep the ball movie clip as a local variable
   var ball:MovieClip = event.target.loader.content as MovieClip;
   ball.name = "ball";
   ball.addEventListener( "End of Movie" , remove , false , 0 , true );
   addChild( ball);
}

function remove(event:Event):void
{ 
   event.target.removeEventListener( 'End of Movie' , remove );

   //now you can retrieve the ball mc by its name and remove it from the stage
   this.removeChild( this.getChildByName('ball') );
}

这篇关于当外部SWF已达到帧x,我怎么卸载呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 08:10