A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: how do I remove a movieclip instance?

  1. #1
    Member
    Join Date
    Mar 2004
    Posts
    45

    how do I remove a movieclip instance?

    Hi everyone,

    I'm new to AS3, and I'd like to remove a movieclip instance when it reaches its last frame (from the displaylist and memory).

    Firstly, I tried putting code in the last frame of the movieclip like this:
    Code:
    this.parent.removeChild(this);
    but this didn't work.

    Secondly, I thought that where I create the instance I would store a reference to this instance, and add an event listener that tests what frame the instance is on, and if currentFrame == lastFrame then set the reference to null.

    My code looks like this, but it doesn't work:

    Code:
    rippleReference.addEventListener(Event.ENTER_FRAME, rippleDecay);
    		
    public function rippleDecay(evt:Event) {
    	if (evt.target.currentFrame==50){
    		evt.target = null;
    	}
    }
    I'd be really grateful if anyone could help me with this...

    Cheers,

    SamuraiDave

  2. #2
    Member
    Join Date
    Mar 2004
    Posts
    45

    this works...

    I tried casting the information i get back in event.target to movieclip and then removing and it worked.

    I'm not sure it's actually removing the reference from memory though....
    Here is the code:

    Code:
    public function rippleDecay(evt:Event):void {
    			if (MovieClip(evt.target).currentFrame == 50) {
    				MovieClip(evt.target).parent.removeChild(MovieClip(evt.target));
    				delete MovieClip(evt.target);
    			}
    		}
    Is there a better way to do this?
    By adding the event listener to my movieclip instance, will it eventually be deleted from memory also by the "delete MovieClip(evt.target)" line?
    or will this simply create a new reference through casting and therefore delete only the new reference (while the old reference sits there wasting memory)?

    Help! too many references are making my head crazy! hehe >_<

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center