子供のコンテナ管理に少し問題があります。実際には、それは多くの子供を持っており、そのy座標は非常にランダムです。AS3のコンテナの子供たちを再注文するには
とにかく、私はy座標で注文することができますか?下部は正面に、高くなると背面にあることになりますか?
私は2 "for"でできることは何ですか?
はあなたの助けをありがとう^^
子供のコンテナ管理に少し問題があります。実際には、それは多くの子供を持っており、そのy座標は非常にランダムです。AS3のコンテナの子供たちを再注文するには
とにかく、私はy座標で注文することができますか?下部は正面に、高くなると背面にあることになりますか?
私は2 "for"でできることは何ですか?
はあなたの助けをありがとう^^
//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]);
}
これは、スパークコンポーネント用。あなたはgetElementAt()
とaddElement()
あなたはy
に関してソートする重なり順をしたいようですね。
addChildAt(child:DisplayObject, index:int)
ゼロのインデックスはDISPLAYLISTの下を表し、numChildren - 1
がトップを表します
あなたは、このメソッドを使用することができます。
詳細はAS3言語リファレンスを確認してください:flash.display.DisplayObjectContainer
の代わりにgetChildAt()
とaddChild()
の代わりにmxコンポーネントを使用しても同じことができます。 yはランダムに作成されるため、インデックスの値を知ることはできません。 –
他の人が私を殴ったようです。基本的には、配列に子を配置し、yに関して並べ替えを実行し、並べ替えられた配列のそれぞれのインデックスを使用してDisplayObjectを並べ替える必要があります。 – Peter
これはあなたのコンテナがcontainer
の名前とコード(未テスト)と同じスコープ内に存在している前提としています
//prepare an array
var sortArray:Array = [];
//put the children into an array
for(var i:int = 0; i < container.numChildren; i++) {
sortArray[i] = container.getChildAt(i);
}
//get a sorting function ready
function depthSort(a:MovieClip,b:MovieClip):int
{
return a.y - b.y;
}
//sort the array by y value low -> high
sortArray.sort(depthSort);
//loop through the array resetting indexes
for(i = 0; i <sortArray.length; i++) {
container.setChildIndex(sortArray[i],i);
}
私たちはむしろ同時に思うようです;)2日で2回目です。 – RIAstar
あなたのものは一生懸命だった。 – shanethehat
もちろんvar要素:Array = [count];間違っている、それはされている必要があります var elements:Array = new Array(count); まだそれは役に立ちませんが、それは次のようにも動作します: var elements:Array = []; –
これは超高齢ですが、あなたは正しいです。一定 – RIAstar