Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 250

Programming actionscript 3.0
Table of Contents

Advertisement

As with all objects, declaring an Array instance is only half the job of creating an Array. Before
accessing an Array instance's properties or methods, it must be instantiated, which is done in
the PlayList class's constructor.
public function PlayList()
{
this._songs = new Array();
// Set the initial sorting.
this.sortList(SortProperty.TITLE);
}
The first line of the constructor instantiates the
In addition, the
sortList()
Adding a song to the list
When a user enters a new song into the application, the code in the data entry form calls the
PlayList class's
addSong()
/**
* Adds a song to the playlist.
*/
public function addSong(song:Song):void
{
this._songs.push(song);
this._needToSort = true;
}
Inside
, the
addSong()
was passed to
addSong()
element is added to the end of the array, regardless of any sorting that might have been
applied previously. This means that after the
is likely to no longer be sorted correctly, so the
the
method could be called immediately, removing the need to keep track of
sortList()
whether the list is sorted or not at a given time. In practice, however, there is no need for the
list of songs to be sorted until immediately before it is retrieved. By deferring the sorting
operation, the application doesn't perform sorting that is unnecessary if, for example, several
songs are added to the list before it is retrieved.
250
Working with Arrays
method is called to set the initial sort-by property.
method.
array's
_songs
push()
as a new element in that array. With the
variable, so that it is ready to be used.
_songs
method is called, adding the Song object that
method has been called, the list of songs
push()
variable is set to
_needToSort
method, the new
push()
. In theory,
true

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents