这是我的swf加载代码:
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帧,然后将其卸载。有没有办法在不下载其他类的情况下执行此操作?
答案 0 :(得分:1)
在球影片剪辑的第244帧中,您可以发送一个事件来通知MainTimeline已经到达第244帧,然后您将需要删除对球mc的所有引用,并让垃圾收集从那里处理它。 / p>
//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') ); }
答案 1 :(得分:0)
订阅舞台的Event.ENTER_FRAME
事件并检查您创建的影片剪辑的currentFrame属性。
private static final BALL_END_FRAME : int = 244;
private var _ball : MovieClip;
function onCompleteHandler(event:Event):void
{
_ball = event.target.loader.content as MovieClip;
addChild(_ball);
stage.addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
}
function onEnterFrameHandler(event:Event):void
{
if (_ball.currentFrame == BALL_END_FRAME)
{
removeChild(_ball);
stage.removeEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
}
}