Dynamically Change the Child Depth in the Layout
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:s="library://ns.adobe.com/flex/spark"> <mx:Script> import mx.core.IVisualElement; import spark.components.supportClasses.GroupBase; private var currentIndex:int = 0; private function swapDepths():void { var layoutTarget:GroupBase = bLayout.target; var element:IVisualElement; for( var i:int = 0; i < layoutTarget.numElements; i++ ) { element = layoutTarget.getElementAt( i ) as IVisualElement; element.depth = i; } } </mx:Script> <s:Group> <s:layout> <s:BasicLayout id="bLayout" /> </s:layout> <mx:Button x="0" depth="100" label="(1) button" /> <mx:Button x="30" depth="100" label="(2) button" /> <mx:Button x="90" label="(3) button" /> </s:Group> <mx:Button label="swapDepths" click="swapDepths();" /> </mx:Application>