Skip to main content
Gleaj522
Known Participant
March 12, 2013
Answered

alphabetizing xml filled dynamic textfields

  • March 12, 2013
  • 1 reply
  • 2277 views

So I am looking to alphabetize dynamically created textfield created using a for each loop and XML.

How would I go about this, I searched around and there isn't much about this, and now I feel like I haven't the slightest clue. The one post I found is missing it's own created Utilities class (I believe):

http://help.mfazio.com/?p=75&cpage=1#comment-39.

So where do I even begin?

Thanks for any help in advance! I'm still learning so the more you explain it, the more I learn (Thanks).

This topic has been closed for replies.
Correct answer kglad

add your textfields to an array and sort it using a custom sort function:

// after text is assigned:

var tfA:Array=[array of textfields];

tfA.sort(sortByText);

function sortByText(tf1:TextField,tf2:TextField):int{

if(tf1.text<tf2.text){

return -1;

} else if(tf1.text>tf2.text){

return 1;

} else {

return 0;

}

}

1 reply

kglad
Community Expert
Community Expert
March 12, 2013

are you alphabetizing based on textfield name?  textfield text?  something else?

Gleaj522
Gleaj522Author
Known Participant
March 12, 2013

I'm alphabetizing by textfield text.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
March 12, 2013

add your textfields to an array and sort it using a custom sort function:

// after text is assigned:

var tfA:Array=[array of textfields];

tfA.sort(sortByText);

function sortByText(tf1:TextField,tf2:TextField):int{

if(tf1.text<tf2.text){

return -1;

} else if(tf1.text>tf2.text){

return 1;

} else {

return 0;

}

}