# getchildIndex help

**URL:** <https://forum.kirupa.com/t/getchildindex-help/302223>\
**Category:** flash\
**Created:** [December 23, 2009, 6:43pm UTC](https://forum.kirupa.com/t/getchildindex-help/302223 "2009-12-23T18:43:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Navarone](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@Navarone](https://forum.kirupa.com/u/Navarone)\
**Post date:** [December 23, 2009, 6:43pm UTC](https://forum.kirupa.com/t/getchildindex-help/302223/1 "2009-12-23T18:43:26Z")

</div>

I have a function called addRoom. A scroll pane with thumbnails of rooms, each thumbnail is a button. The viewport is empty by default. When I click a button the function is called, it adds a room to my viewport. If I click another button a new room is added but the first room still remains. How do I get the first room to be removed? I assume there is something wrong with my index.

```auto

// add room image to the viewport
function addRoom(event:MouseEvent):void {
    //trace(rmPictures[event.currentTarget]);
    var rmloader:Loader = new Loader();
    rmloader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop, false, 0, true);
    rmloader.contentLoaderInfo.addEventListener(Event.COMPLETE, done, false, 0, true);
    rmloader.load(new URLRequest(rmPictures[event.currentTarget]));
    rmloader.x = 0;
    rmloader.y = 0;
    roomContainer.addChild(rmloader);

    //index the room as children
    var roomPosition:uint = roomContainer.numChildren - 1;
    roomContainer.setChildIndex(rmloader, roomPosition);
    //remove room on level one when adding another room.
    if (roomContainer.getChildIndex(rmloader) == 2) {
        roomContainer.removeChildAt(1);
    }
    //removeChild(myScrollPane);
    //removeChild(myContainer);
    //removeChild(texturePane);
    //removeChild(roomPane);
    colorText.alpha = 0;
}

```
