Posted By

chrisaiv on 12/16/08


Tagged

as3 stage


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

THEPWN3R
themill
donaldleegraham
tspitzr


AS3: Safely remove content from the Stage


 / Published in: ActionScript 3
 

There are times when I'm constantly adding and removing a child. For example, when I'm trying to throw out alerts to a user, I'll addChild( alertMc) then removeChild( alertMc ) when I'm done. Sometimes things get a bit tricky and I'll mistakenly call removeChild() when content is no longer available on stage. To remedy this, what I do now is call my function removeContent( stage, "nameOfMcLoaderanything") and it will first make sure that my target is on the stage before it removes it.

  1. private function removeContent( stg:Stage, childName:String ):void
  2. {
  3. if( stg.getChildByName( childName ) != null){
  4. //J. If var transparencyMc has been loaded, test if it's currently visible. If it is, then remove it from the stage
  5. if( stg.getChildByName( childName ).visible ) stg.removeChild( stg.getChildByName( childName ) );
  6. }
  7. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: viaria on June 16, 2011

when we call removeChild, it is all removed from stage but it is initted, how we can delete it from memory. there is bug in FP about this.

Posted By: chrisaiv on June 23, 2011

Removing an object from the stage is not the same as removing it from memory. If you want to remove any object from memory, simply set it to null.

For example: myObject = null;

You need to login to post a comment.