Wow, works like a charm; big thanks. 

And if I want to test it against IDs with 3 characters I'm thinking that 
RegExes are the way to go. Here's what I've got that isn't quite working. 

var currentID:String = item.id.toString();
var pattern:RegExp = /^<currentID>/; 
            
if ( pattern.test( activeID ) )
      return true;
else
      return false;

I'm thinking my pattern will test for the currentID (no matter how many 
characters) at the beginning of the activeID. But it's not making any matches. 
Am I that far off? 

--- In [email protected], "Tracy Spratt" <tr...@...> wrote:
>
> Assuming strings:
> 
> If (currentID.charAt(0) == activeID)  {                       //if the first
> character matches the activeId
> 
>             return true;
> 
> }
> 
> Else  {
> 
>             return false;
> 
> }
> 
>  
> 
>  
> 
> If the ids are numbers then the logic will be different.
> 
>  
> 
> Tracy Spratt,
> 
> Lariat Services, development services available
> 
>   _____  
> 
> From: [email protected] [mailto:[email protected]] On
> Behalf Of fumeng5
> Sent: Saturday, May 02, 2009 5:19 PM
> To: [email protected]
> Subject: [flexcoders] Re: Sorting VBox elements based on an XML ID
> 
>  
> 
> 
> 
> 
> 
> 
> I'm creating an ArrayCollection based on the XML loaded in. I iterate over
> that and build the UI. I have a simple conditional that decides whether to
> run one block of code and create a button or run another and create a radio
> button. I think that part is fine as it is right now. 
> 
> I've never worked with a Filter function before but what I'm understanding
> is that I can get the ID for the button clicked without a problem. I've
> tested that and it works. I just don't know how to compare that ID with all
> the other IDs and return only the ones I want.
> 
> This is what I have so far for the Filter function:
> 
> private function stateFilterFunc(item:Object):Boolean {
> var currentID:String = item.id; // The ID of the current item in the
> DataProvider
> var activeID:String = buttonID; // The ID of the button clicked on
> 
> if ( (activeID< currentID) )
> return true;
> else
> return false;
> }
> 
> So, how do I build the conditional that'll allow me to, in the case where ID
> = 1, filter to show IDs that have 1, 11, 12, 13, etc...
> 
> And the IDs are 1 and 2 characters. 
> 
> Thank you for your help.
> 
> Matt
> 
> --- In flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com,
> "Tracy Spratt" <tracy@> wrote:
> >
> > In that case I would create a component that had two states, one radio and
> > one button, and repeat that, passing in the entire currentItem in a setter
> > function, and set the state based on the passed in data.
> > 
> > 
> > 
> > On the filter, are you asking for an e4x expression?
> > 
> > 
> > 
> > One tip is that in an e4x expression, you can use a function in place of
> > in-line expressions, pass a ref to the current node into the function, do
> > whatever logic and return a Boolean if the node should be included.
> > 
> > 
> > 
> > Are all the ids 1 or 2 chars only?
> > 
> > 
> > 
> > Tracy Spratt,
> > 
> > Lariat Services, development services available
> > 
> > _____ 
> > 
> > From: flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com
> [mailto:flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com]
> On
> > Behalf Of fumeng5
> > Sent: Saturday, May 02, 2009 11:58 AM
> > To: flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com
> > Subject: [flexcoders] Re: Sorting VBox elements based on an XML ID
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > I've got it almost working now. However, I'm trying to write a Filter
> > function. This function will compare an ID and return a subset of IDs.
> > 
> > For example, an ID of 1 will return IDs with 11, 12, 13; an ID of 2 will
> > return IDs with 21, 22, 23, etc...
> > 
> > How do I compare IDs as strings to return what I want? Any tip in the
> right
> > direction is greatly appreciated. 
> > 
> > --- In flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com,
> > "fumeng5" <fumeng5@> wrote:
> > >
> > > Hmmm...I didn't know about the Repeater component, that's quite useful.
> > However, I should have explained that I'm not working with all the same
> > components. The XML is more complex than I posted. 
> > > 
> > > Here's what it really looks like:
> > > 
> > > <Class> 
> > > <Class_ID>1</Class_ID>
> > > <Class_Name>First Class</Class_Name>
> > > <Class_Amount></Class_Amount>
> > > </Class>
> > > 
> > > <Class> 
> > > <Class_ID>2</Class_ID>
> > > <Class_Name>Second Class</Class_Name>
> > > <Class_Amount>1.31</Class_Amount>
> > > </Class>
> > > 
> > > <Class> 
> > > <Class_ID>11</Class_ID>
> > > <Class_Name>Subclass of first class</Class_Name>
> > > </Class>
> > > 
> > > So my conditional for building the UI goes like this; if Class_Amount is
> > empty, this element has a subclass, i.e. 
> > > 
> > > for (var i:int=0; i<classData.length; i++){
> > > 
> > > if(classDataNode.Class_Amount == ''){
> > > var myButton:Button = new Button();
> > > myButton.label = classData[i].Class_Name;
> > > addChild( myButton );
> > > }else{
> > > var myRadioButton:RadioButton = new RadioButton();
> > > myRadioButton.label = classData[i].Class_Name;
> > > addChild( myRadioButton );
> > > }
> > > }
> > > 
> > > I guess that with this scenario I'm not able to use the Repeater
> compnent
> > and will be forced to create a custom sorting of VBox child elements. 
> > > 
> > > Is that right? 
> > > 
> > > --- In flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com>
> ups.com,
> > "Tracy Spratt" <tracy@> wrote:
> > > >
> > > > Use Repeater, and then just sort the dataProvider.
> > > > 
> > > > 
> > > > 
> > > > Tracy Spratt,
> > > > 
> > > > Lariat Services, development services available
> > > > 
> > > > _____ 
> > > > 
> > > > From: flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com>
> ups.com
> > [mailto:flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com]
> > On
> > > > Behalf Of fumeng5
> > > > Sent: Friday, May 01, 2009 3:15 PM
> > > > To: flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com
> > > > 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