要手动更改索引的顺序,请使用addChildAt (DisplayObject, index)
两个显示对象索引开关。请使用以下内容。swapChildren(DisplayObject1,DisplayObject2)
swapChildrenAt(index1,index2)
如果您看下图,舞台中有实例 MovieClip 6。但索引是任意的。取决于真正从库中创建订单或拖放订单。所以我根据顺序按名称重新排序索引。
import flash.display.MovieClip;
var mc:MovieClip;
for(var i:int = 0; i<this.numChildren; i++)
{
mc = this.getChildAt(i) as MovieClip;
trace("before clipName: " + mc.name);
}
//re-ordering
for(i = 0; i<this.numChildren; i++)
{
mc = this.getChildByName("mc"+i) as MovieClip;
addChildAt(mc,i);
}
for(i = 0; i<this.numChildren; i++)
{
mc = this.getChildAt(i) as MovieClip;
trace("after clipName: " + mc.name);
}
console:
before clipName: mc1
before clipName: mc4
before clipName: mc3
before clipName: mc5
before clipName: mc2
before clipName: mc0
after clipName: mc0
after clipName: mc1
after clipName: mc2
after clipName: mc3
after clipName: mc4
after clipName: mc5