mechanicarts
mechanicarts

Reputation: 171

Index out of bounds on setChildIndex?

OK so I have the following code...

function fire1(e:MouseEvent)
{
    firebb.addChild(fireb);
    fireb.x=firebb.x;
    fireb.y=firebb.y;
    fireb.parent.setChildIndex(fireb, numChildren-1);
    fireb.startDrag();
    pop.play();
}

what it's supposed to do, is create a child of the firebb Movieclip and change its depth (I use a custom cursor which is supposed to be on top of everything...but then I get this error when my game reaches this point.

RangeError: Error #2006: The supplied index is out of bounds.
    at flash.display::DisplayObjectContainer/setChildIndex()
    at main_fla::MainTimeline/fire1()

setChildIndex worked flawlessly in previous frames, what's wrong now?

Upvotes: 0

Views: 725

Answers (1)

jyf
jyf

Reputation: 11

fireb.parent.addChild(firWb);

or

fireb.parent.numberChildren -1

Upvotes: 1

Related Questions