[英]Flash AS3 how to set the index of a button on the stage?
我大约有60个按钮手动添加到了时间轴。 我需要指定每个的索引,但是索引的给出取决于我将对象从库中放到舞台上的顺序。 我不想通过编程方式指定每个按钮的索引名称,因为没有易于遵循的模式。
private function buttonHandler(event:MouseEvent):void
{
event.target.parent.getChildIndex(event.target));
}
我可以得到所有这样的索引,但它们的顺序不符合我想要的顺序。 谢谢
若要手动更改索引的顺序,如果要“两个displayobject”索引开关,请使用addChildAt (DisplayObject, index)
。 请使用以下内容。 swapChildren(DisplayObject1,DisplayObject2)
swapChildrenAt(index1,index2)
如果您看下面的图片,则舞台上有实例MovieClip 6。 但是索引是任意的。 取决于真正从libary创建顺序或拖放顺序。 所以我要根据顺序按名称重新排序索引。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.