Daniel O'Hara
Daniel O'Hara

Reputation: 13

Flash Professional Error 2006

I have looked over this and I must be blind as I cannot see what the problem is. I looked a bit online and tried to modify it to work, but no luck.

function dragTheObject(event:MouseEvent):void { 
    var item:MovieClip = MovieClip(event.target); 
    item.startDrag();
    var topPos:uint = (item, numChildren > 0 ? numChildren-1 : 0); 
    this.parent.setChildIndex(item, topPos);
} 

Upvotes: 1

Views: 70

Answers (1)

akmozo
akmozo

Reputation: 9839

The AS3 #2006 runtime error ( RangeError: Error #2006: The Supplied Index is Out of Bounds ) is fired by this line :

this.parent.setChildIndex(item, topPos);

because your trying to set an index to your item object which is greater than (or equal to) the DisplayObjectContainer's (this.parent) numChildren property.

So to put your object on the top, you can simply do :

function dragTheObject(event:MouseEvent):void 
{
    var item:MovieClip = MovieClip(event.target);
        item.startDrag();

    item.parent.setChildIndex(item, item.parent.numChildren - 1);
}

Hope that can help.

Upvotes: 1

Related Questions