ComboBox.sortItems()

Availability

Flash Player 7.

Edition

Flash MX Professional 2004.

Usage

comboBoxInstance.sortItems([compareFunc], [optionsFlag])

Parameters

compareFunc A reference to a function that compares two items to determine their sort order. For details, see Array.sort() in ActionScript 2.0 Language Reference. This parameter is optional.

optionsFlag Lets you perform multiple sorts of different types on a single array without having to replicate the entire array or re-sort it repeatedly. This parameter is optional.

The following are possible values for optionsFlag:

You can combine these options into one value. For example, the following code combines options 3 and 1:

array.sort (Array.NUMERIC | Array.DESCENDING)

Returns

Nothing.

Description

Method; sorts the items in the combo box according to the specified compare function or according to the specified sort options.

Example

This example sorts according to uppercase labels. The items a and b are passed to the function and contain label and data fields:

myComboBox.sortItems(upperCaseFunc);
function upperCaseFunc(a,b){
    return a.label.toUpperCase() > b.label.toUpperCase();
}

The following example uses the upperCaseFunc() function defined above, along with the optionsFlag parameter to sort the elements of a ComboBox instance named myComboBox:

myComboBox.addItem("Mercury");
myComboBox.addItem("Venus");
myComboBox.addItem("Earth");
myComboBox.addItem("planet");
myComboBox.sortItems(upperCaseFunc, Array.DESCENDING);
// The resulting sort order of myComboBox will be:
// Venus
// planet
// Mercury
// Earth