# removeChild? I want to remove the previous child before adding a new Child

**URL:** https://forum.kirupa.com/t/removechild-i-want-to-remove-the-previous-child-before-adding-a-new-child/238799
**Category:** Uncategorized
**Created:** [September 15, 2007, 10:26am UTC](https://forum.kirupa.com/t/removechild-i-want-to-remove-the-previous-child-before-adding-a-new-child/238799 "2007-09-15T10:26:37Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![stuluk28](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/stuluk28/32/2775_2.png) [@stuluk28](https://forum.kirupa.com/u/stuluk28)
#### Post date: [September 15, 2007, 10:26am UTC](https://forum.kirupa.com/t/removechild-i-want-to-remove-the-previous-child-before-adding-a-new-child/238799/1 "2007-09-15T10:26:37Z")

</div>

I tinkered with AS3 a few months back, but don’t have ANY of the old scripts and can’t remember much.

I’m calling a method to add a new MovieClip to the Stage from the library, I’ve got that setup and working but each new instance overlay’s the old one and doesn’t replace.

I clearly need to removeMovieClip() but that is an AS2 function not AS3?

removeChild returns an error:

\*\*  
TypeError: Error #2007: Parameter child must be non-null.  
at flash.display::DisplayObjectContainer/removeChild()  
at LukeSturgeon/loadPage()  
at LukeSturgeon/navButtonHandler()  
\*\*

my two key functions are:

\*\*  
/\*\*  
\* loadPage method  
_/  
public function loadPage(page\_str:String):void {  
removeChild(page)  
var page:MovieClip = getPage(page\_str);  
///  
page.x = padding\_left;  
page.y = padding\_top;  
this.addChild(page);  
}  
/_\*  
\* getPage method  
\*/  
private function getPage(page\_str):MovieClip {  
var new\_page:MovieClip;  
///  
switch (page\_str) {  
case “Profile” :  
new\_page = new Profile();  
break;  
case “Contact” :  
new\_page = new Contact();  
break;  
default :  
new\_page = new Work();  
}  
return new\_page;  
}

this version (minus the removeChild line) is viewable at [http://www.lukesturgeon.co.uk/as3](http://www.lukesturgeon.co.uk/as3)

any thoughts? it’s probably so simple!!!
