Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 251

Programming actionscript 3.0
Table of Contents

Advertisement

Sorting the list of songs
Because the Song instances that are managed by the playlist are complex objects, users of the
application may wish to sort the playlist according to different properties, such as song title or
year of publication. In the PlayList application, the task of sorting the list of songs has three
parts: identifying the property by which the list should be sorted, indicating what sorting
options need to be used when sorting by that property, and performing the actual sort
operation.
Properties for sorting
A Song object keeps track of several properties, including song title, artist, publication year,
filename, and a user-selected set of genres in which the song belongs. Of these, only the first
three are practical for sorting. As a matter of convenience for developers, the example includes
the SortProperty class, which acts as an enumeration with values representing the properties
available for sorting.
public static const TITLE:SortProperty = new SortProperty("title");
public static const ARTIST:SortProperty = new SortProperty("artist");
public static const YEAR:SortProperty = new SortProperty("year");
The SortProperty class contain three constants,
stores a String containing the actual name of the associated Song class property that can be
used for sorting. Throughout the rest of the code, whenever a sort property is indicated, it is
done using the enumeration member. For instance, in the PlayList constructor, the list is
sorted initially by calling the
// Set the initial sorting.
this.sortList(SortProperty.TITLE);
Because the property for sorting is specified as
according to their title.
TITLE
method, as follows:
sortList()
SortProperty.TITLE
,
, and
, each of which
ARTIST
YEAR
, the songs are sorted
Example: PlayList
251

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents