Return to Snippet

Revision: 10292
at December 16, 2008 13:20 by chrisaiv

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

Initial URL

Initial Description
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, "nameOfMc_Loader_anything") and it will first make sure that my target is on the stage before it removes it.

Initial Title
AS3: Safely remove content from the Stage

Initial Tags

Initial Language
ActionScript 3