# removeChild but don't know where or how

**URL:** <https://forum.kirupa.com/t/removechild-but-dont-know-where-or-how/293805>\
**Category:** flash\
**Created:** [August 4, 2009, 6:59am UTC](https://forum.kirupa.com/t/removechild-but-dont-know-where-or-how/293805 "2009-08-04T06:59:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![spyderfx](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@spyderfx](https://forum.kirupa.com/u/spyderfx)\
**Post date:** [August 4, 2009, 6:59am UTC](https://forum.kirupa.com/t/removechild-but-dont-know-where-or-how/293805/1 "2009-08-04T06:59:22Z")

</div>

I keep getting this Error

RangeError: Error #2006: The supplied index is out of bounds.  
at flash.display::DisplayObjectContainer/addChildAt()  
at stage\_fla::MainTimeline/frame2()  
TypeError: Error #1009: Cannot access a property or method of a null object reference.  
at navbar\_fla::MainTimeline/frame1()

And have come to the conclusion that I need to use a removeChild() in my code from what I have been reading. Problem is I don’t know where to do that.

```auto
var imageRequest:URLRequest = new URLRequest("navbar.swf");
var navbar_mc:Loader = new Loader();
var externalSwf:Object;
navbar_mc.load(imageRequest);
addChild(navbar_mc);
addChildAt(this.navbar_mc, 4);
navbar_mc.addEventListener(Event.COMPLETE, grabContent);

function grabContent(event:Event):void
{
   externalSwf = event.target.content;
   nextFunction();
}
 
function nextFunction():void
{
   externalSwf.childMethod();
   externalSwf.someProperty = 15;
}

```

How do I write the removeChild in so that this error stops popping up? The swf works fine I just want to make sure there are no errors just in case.
