Once we've created an array, we'll inevitably want to retrieve
or change the value of its elements. To do so, we use the
array access operator,
To access an individual element, we provide a reference to the array followed by the element's index within square brackets, as follows:
In the preceding code,
a reference to the array (usually a variable with an array as a
elementNumber is an integer
specifying the element's index. The first element is number 0, and
the last element number is 1 less than the array's length.
Specifying an element number greater than the last valid element
number causes ActionScript to return
undefined (because the specified index is
outside the bounds of the array).
Let's try retrieving some element values. The following code
creates an array using an array literal, and assigns it to the
var trees:Array = ["birch", "maple", "oak", "cedar"];
The following code assigns the value of the first element of
trees ("birch") to a variable,
var firstTree:String = trees;
The following code assigns the third element's value ("oak")
to the variable
(remember that indexes start at 0, so index 2 is the third
var favoriteTree:String = trees;
Now here's the fun part. Because we can specify the index of an element as any number-yielding expression, we can use variables or complex expressions just as easily as we use numbers ...