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);
}
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?
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') ); }