# Help with Sprites

**URL:** https://forum.kirupa.com/t/help-with-sprites/320374
**Category:** flash
**Created:** [March 22, 2011, 3:11am UTC](https://forum.kirupa.com/t/help-with-sprites/320374 "2011-03-22T03:11:08Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![lozts](https://avatars.discourse-cdn.com/v4/letter/l/f9ae1b/32.png) [@lozts](https://forum.kirupa.com/u/lozts)
#### Post date: [March 22, 2011, 3:11am UTC](https://forum.kirupa.com/t/help-with-sprites/320374/1 "2011-03-22T03:11:08Z")

</div>

I am using a sprite as a container so that when the users chooses a new item from a combobox, the sprites contained in the container sprite can be removed but for some reason it keeps displaying this error:  
“RangeError: Error #2006: The supplied index is out of bounds.”

Here is the sprite I create outside of all functions and some global variables:

```auto

var container:Sprite=new Sprite(); 
this.addChild(container);
var numCircles:int = 0;
var compareValue:int = 0;
var VxNum:Number = -89;

```

Then I have a function that creates circles based on what is read from an xml file (which is what avgData contains) and adds them to the sprite container:

```auto

var yNum:Number = 104;
var i:int;

for(i=0; i<avgData.length; i++)
{
var circle:Sprite = new Sprite();
numCircles+=1;

circle.graphics.lineStyle(1, 0x000000, 1);
circle.graphics.beginFill(0x003366,1);

if(compareValue==0)
{
    circle.graphics.drawCircle(150, 150, (avgData*[2]*5.25));
}
else
{
    circle.graphics.drawCircle(150, 150, (avgData*[3]*2));
}

circle.graphics.endFill();
circle.x = VxNum;
circle.y = yNum;
circle.alpha = .5;

container.addChildAt(circle, container.numChildren);

VxNum = VxNum + 20;
}

```

then finally I have a function that is called if a combobox’s value is changed which will remove all the graphics and children inside the container:

```auto

function getItem(event:Event):void
{
    var i:int;
    for(i=0;i<numCircles;i++)
    {
        
        Sprite(container.getChildAt(i)).graphics.clear();
        
        Sprite(container.getChildAt(i)).removeChildAt(0); 
        
    }
    
    while(container.numChildren>0)
    {
        container.removeChildAt(0);
    }
    
    numCircles=0;
}

```

However, I keep getting that error:  
“RangeError: Error #2006: The supplied index is out of bounds.”  
when it reaches this line:  
Sprite(container.getChildAt(i)).removeChildAt(0);

Can anybody tell me why?

I’d greatly appreciate it,  
lOzts
