User Guide
Example: PlayList 249
Example: PlayList
The PlayList example demonstrates techniques for working with arrays, in the context of a
music playlist application that manages a list of songs. These techniques are:
■ Creating an indexed array
■ Adding items to an indexed array
■ Sorting an array of objects by different properties, using different sorting options
■ Converting an array to a character-delimited string
The PlayList application files can be found in the Samples/PlayList folder. The application
consists of the following files:
PlayList class overview
The PlayList class manages a set of Song objects. It has public methods with functionality for
adding a song to the playlist (the
addSong() method) and sorting the songs in the list (the
sortList() method). In addition, the class includes a read-only accessor property, songList,
which provides access to the actual set of songs in the playlist. Internally, the PlayList class
keeps track of its songs using a private Array variable:
public class PlayList
{
private var _songs:Array;
private var _currentSort:SortProperty = null;
private var _needToSort:Boolean = false;
...
}
In addition to the _songs Array variable, which is used by the PlayList class to keep track of
its list of songs, two other private variables keep track of whether the list needs to be sorted
(
_needToSort) and which property the song list is sorted by at a given time (_currentSort).
File Description
PlayListApp.mxml The main application file in MXML for Flex.
com/example/programmingas3/playlist/
PlayList.as
Provides the playlist functionality for the
application, such as adding and sorting songs.
com/example/programmingas3/playlist/
Song.as
A value object representing information about a
single song. The items that are managed by the
PlayList class are Song instances.
com/example/programmingas3/playlist/
SortProperty.as
A pseudo-enumeration whose available values
represent the properties of the Song class by
which a list of Song objects can be sorted.