Flash 专业错误 2006

Flash Professional Error 2006

我看过了,我一定是瞎了,看不出是什么问题。我在网上看了看并尝试修改它以使其工作,但没有成功。

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);
} 

AS3 #2006 运行时错误 (RangeError: Error #2006: The Supplied Index is Out of Bounds) 由以下行引发:

this.parent.setChildIndex(item, topPos);

因为您试图为您的 item 对象设置索引,该索引大于(或等于)DisplayObjectContainer 的 (this.parent) numChildren 属性.

所以要将您的对象放在顶部,您可以简单地执行以下操作:

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

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

希望能帮到你。