本文介绍了我怎样才能重新整理我的容器在AS3的孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在管理孩子我的容器有点麻烦。事实是,它有很多的儿童及其y坐标是很随意的。
反正是有,我可以命令他们用y坐标,较低的将是正面和高于在后面?
是什么事情,我可以用2做为?
感谢您的帮助^^
在我们的组成元素解决方案
//数
VAR计数:INT = numElements个;
VAR元素:数组= [];
//加载组件的所有元素到数组
对于(VAR我:= 0; I<计数;我++){
元素[I] = getElementAt(我);
}
//根据他们的'Y'属性的数组元素进行排序
elements.sortOn(Y,Array.NUMERIC来);
//元件重新添加到组件
//在我们刚刚创建的排序数组的顺序。
//当我们使用的addElement'添加的元素它会
//在组件的图像显示的顶部被添加
//并会自动从原来的位置移开。
对于(i = 0; I<计数;我++){
的addElement(元素[I]);
}
这是Spark组件。您可以通过做同样的事情与MX组件 getChildAt()
和的addChild()
而不是 getElementAt()
和的addElement()
I have a little trouble in managing the children my container. The fact is that it has a lot of children and their y coordinates are very random.
Is there anyway i can order them by y coordinates that the lower will be in the front and the higher with be in the back?
is it something that that I can do with 2 "for"?
Thank you for your help ^^
解决方案
//the number of elements in our component
var count:int = numElements;
var elements:Array = [];
//load all the elements of the component into an Array
for (var i:int=0; i<count; i++) {
elements[i] = getElementAt(i);
}
//sort the Array elements based on their 'y' property
elements.sortOn("y", Array.NUMERIC);
//re-add the element to the component
//in the order of the sorted Array we just created.
//When we add the element using 'addElement' it will
//be added at the top of the component's displaylist
//and will automatically be removed from its original position.
for (i=0; i<count; i++) {
addElement(elements[i]);
}
This is for Spark components. You can do the exact same thing with mx components using getChildAt()
and addChild()
instead of getElementAt()
and addElement()
这篇关于我怎样才能重新整理我的容器在AS3的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!