ComboBox.sortItemsBy()

Availability

Flash Player 7.

Edition

Flash MX Professional 2004.

Usage

comboBoxInstance.sortItemsBy(fieldName, order [optionsFlag])

Parameters

fieldName A string that specifies the name of the field to use for sorting. This value is usually "label" or "data".

order A string that specifies whether to sort the items in ascending order ("ASC") or descending order ("DESC").

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, but if used, should replace the order parameter.

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 alphabetically or numerically, in the specified order, using the specified field name. If the fieldName items are a combination of text strings and integers, the integer items are listed first. The fieldName parameter is usually "label" or "data", but advanced programmers may specify any primitive value. If you want, you can use the optionsFlag parameter to specify a sorting style.

Example

The following examples are based on a ComboBox instance named myComboBox, which contains four elements labeled "Apples", "Bananas", "cherries", and "Grapes":

// First, populate the ComboBox with the elements.
myComboBox.addItem("Bananas");
myComboBox.addItem("Apples");
myComboBox.addItem("cherries");
myComboBox.addItem("Grapes");

// The following statement sorts using the order parameter set to "ASC", 
// and results in a sort that places "cherries" at the bottom of the list 
// because the sort is case-sensitive.
myComboBox.sortItemsBy("label", "ASC"); 
// resulting order: Apples, Bananas, Grapes, cherries

// The following statement sorts using the order parameter set to "DESC", 
// and results in a sort that places "cherries" at the top of the list 
// because the sort is case-sensitive.
myComboBox.sortItemsBy("label", "DESC");
// resulting order: cherries, Grapes, Bananas, Apples

// The following statement sorts using the optionsFlag parameter set to 
// Array.CASEINSENSITIVE. Note that an ascending sort is the default setting.
myComboBox.sortItemsBy("label", Array.CASEINSENSITIVE);
// resulting order: Apples, Bananas, cherries, Grapes

// The following statement sorts using the optionsFlag parameter set to 
// Array.CASEINSENSITIVE | Array.DESCENDING.
myComboBox.sortItemsBy("label", Array.CASEINSENSITIVE | Array.DESCENDING);
// resulting order: Grapes, cherries, Bananas, Apples