mercredi 22 avril 2015

Custom Sorting Function

I am trying to sort the contents of a textbox (Which contains the names of people) alphabetically. When the user presses the button, the contents of the textbox is supposed to sort. This is what I have so far:

btn_alpha.addEventListener(MouseEvent.CLICK, alphabeticalSort);


function alphabeticalSort(Sort:Array):Array
{
for (var i:int = 0; i < Sort.length; i++)
{
    var sortArray:int = i;
    for (var ii = i+1; ii < Sort.length; ii++)
    {
        if (Sort[ii]["Name"] < Sort[sortArray]["Name"])
        {
            sortArray = ii;
        }
    }
    var temp:Object;
    temp = Sort[i];
    Sort[i] = Sort[sortArray];
    Sort[sortArray] = temp;
}

return Sort;
}

The program runs, but the textbox isn't sorted when the button is pressed. The only error that comes up is when you try and press the button, it says "TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::MouseEvent@8686881 to Array."

Any suggestions on how to make this work would be appreciated!

Aucun commentaire:

Enregistrer un commentaire