Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 252

Programming actionscript 3.0
Table of Contents

Advertisement

Sorting by property and specifying sort options
The work of actually sorting the list of songs is performed by the PlayList class in the
method, as follows:
sortList()
/**
* Sorts the list of songs according to the specified property.
*/
public function sortList(sortProperty:SortProperty):void
{
...
var sortOptions:uint;
switch (sortProperty)
{
case SortProperty.TITLE:
sortOptions = Array.CASEINSENSITIVE;
break;
case SortProperty.ARTIST:
sortOptions = Array.CASEINSENSITIVE;
break;
case SortProperty.YEAR:
sortOptions = Array.NUMERIC;
break;
}
// Perform the actual sorting of the data.
this._songs.sortOn(sortProperty.propertyName, sortOptions);
// Save the current sort property.
this._currentSort = sortProperty;
// Record that the list is sorted.
this._needToSort = false;
}
When sorting by title or artist, it makes sense to sort alphabetically, but when sorting by year,
it's most logical to perform a numeric sort. The
appropriate sorting option, stored in the variable
specified in the
sortProperty
used to distinguish between properties, rather than hard-coded values.
With the sort property and sort options determined, the
calling its
sortOn()
property is recorded, as is the fact that the song list is currently sorted.
252
Working with Arrays
parameter. Here again the named enumeration members are
method, passing those two values as parameters. The current sort
statement is used to define the
switch
, according to the value
sortOptions
array is actually sorted by
_songs

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents