Use Repeater, and then just sort the dataProvider.

 

Tracy Spratt,

Lariat Services, development services available

  _____  

From: [email protected] [mailto:[email protected]] On
Behalf Of fumeng5
Sent: Friday, May 01, 2009 3:15 PM
To: [email protected]
Subject: [flexcoders] Sorting VBox elements based on an XML ID

 






Hi,

I've got something that I'm trying to troubleshoot and I can't figure it
out. I have an XML file full of elements, i.e.

<Class> 
<Class_ID>1</Class_ID>
<Class_Name>First Class</Class_Name>
</Class>

<Class> 
<Class_ID>2</Class_ID>
<Class_Name>Second Class</Class_Name>
</Class>

<Class> 
<Class_ID>11</Class_ID>
<Class_Name>Subclass of first class</Class_Name>
</Class>

<Class> 
<Class_ID>21</Class_ID>
<Class_Name>Subclass of second class</Class_Name>
</Class>

...

Some classes have subclasses, i.e. Class ID 1 has a subclass of Class ID 11.
And Class ID 2 has a subclass of Class ID 21. 

My XML parsing class creates UI elements based on the XML and adds them to a
VBox, i.e. 

private var classXML:XML;
private var classData:XMLList;

for (var i:int=0; i<classData.length; i++){

var myButton:Button = new Button();
myButton.label = classData[i].Class_Name;

addChild( myButton );
}

When the XML first loads, the elements will be added to the VBox in the way
they're defined in the XML. 

However, I have to add the functionality that if a class is clicked it goes
to the top of the VBox and all its subclasses are listed right under it i.e.
Class ID 1 is clicked, it goes to the top with Class ID 11 right under it. 

This is what I don't know how to do. What is the best way to resort children
in a VBox based on ID? 

Any tips are very much appreciated. 

Thank you. 



Reply via email to