Error 2006 The Supplied Index is Out of Bounds

12,899

Solution 1

The out of range error basically is saying that the value you're providing for the index is "out of range" of the array of indexes in the display object container. The acceptable range is from 0 to n+1 where n is the topmost child's index. Another way to say this is 0 to numChildren. So George is right, you're going to have problems when numChildren - 1 = -1.

If you're trying to add the child to the next-to-top layer, use the if statement above. However, if you're just trying to add it to the top layer, you should either use addChildAt(child, numChildren) or addChild(child) which are synonymous.

Solution 2

Too little code, but that last line: addChildAt(uiBar, numChildren-1); seems to be the problem.

What happens if there are no children added yet (numChildren is 0) ? That should throw an error because you're trying to add uiBar at depth/index -1

try addChildAt(uiBar, numChildren > 0 ? numChildren-1 : 0);

Share:
12,899
londonbird
Author by

londonbird

Yes I'm outnumbered by the other gender when it comes to programming, not so?

Updated on June 04, 2022

Comments

  • londonbird
    londonbird almost 2 years

    Another day another problem unfortunately- the last line of this piece of code is the culprit:

                        uiBar = new mcUiBar();
            uiBar.x=-15;
            uiBar.y=-5;
            addChildAt(uiBar, numChildren-1);
    

    Now I researched and so I know it has something to with the array being larger than whatever, but I'm not figuring it out. I'm stumped. I would appreciate your help. Cheers