Reordering children using the display list API
This
basic example covers a few important concepts. First, the initial
layout contains
six
buttons within a Tile container, each labeled according to its order
within the
Tile.
A button at the bottom is used to call a function to move the last
child to the
beginning
of the Tile container. In moveToTheBeginning( ), the index of the
last child
is
retrieved, which is zero-based. Next, a reference to the last child
in the display list is
obtained
using getChildAt( ). After the last child index is retrieved,
setChildIndex( )
is
called and passes a reference to the button instance and a new index.
--------------------------------------------------------------------------
<?xml
version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
private
function
moveToTheBeginning( ):void
{
//
Retrieve the index of the last child, child indices are zero-based
var
lastChildIndex:int = tileOfLabels.numChildren - 1;
//
Get a reference to the last child
var
child:DisplayObject = tileOfLabels.getChildAt(lastChildIndex);
//
Change the index of the child
tileOfLabels.setChildIndex(child,0);
}
]]>
</mx:Script>
<mx:Tile
id="tileOfLabels">
<mx:HBox
backgroundColor="red"
width="50"
height="50"/>
<mx:HBox
backgroundColor="green"
width="50"
height="50"/>
<mx:HBox
backgroundColor="blue"
width="50"
height="50"/>
<mx:HBox
backgroundColor="black"
width="50"
height="50"/>
</mx:Tile>
<mx:Button
label="Move to the beginning"
click="moveToTheBeginning( )"/>
</mx:Application>
----------------------------------------------------------------------
POSTED BY Abhilash ,WEB and UI Designer AT 6/16/2008 1:09 AM
0
COMMENTS
» POST A COMMENT
| DIGG IT
« BACK HOME
|