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

alphabetizing xml filled dynamic textfields

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 is closed to new replies. Start a new post to keep the conversation going.
kglad
kgladCorrect 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;

}

}

17 replies

kglad
Community Expert
Community Expert
March 12, 2013

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

Translate
Gleaj522
Gleaj522Author
Known Participant
March 12, 2013

I'm alphabetizing by textfield text.

Translate
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;

}

}

Translate