164
Syntax and Language Fundamentals
For more information on modifying arrays, see
“About modifying arrays” on page 166
. For
information on using arrays and about indexes, see
“Using arrays” on page 164
. For
information on adding and removing elements, see
“About adding and removing elements”
on page 168
. For information on the array access operator, see
“Using dot and array access
operators” on page 184
.
You can find a sample source file, array.fla, in the Samples folder on your hard disk. This
sample illustrates array manipulation using ActionScript. The code in the sample creates an
array and sorts, adds, and removes items of two List components. Find the sample file in the
following directories:
■
In Windows, browse to
boot drive
\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\Arrays.
■
On the Macintosh, browse to
Macintosh HD
/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/Arrays.
Using arrays
There are several different ways you can use arrays in your work. You can use them to store
lists of objects, such as a bunch of returned items. If you load data from remote web servers,
you might even receive data as an array of nested objects. Often, arrays contain data in a
similar format. For example, if you build an audio application in Flash, you might have a
user’s playlist stored as an array of song information, stored in objects. Each object contains
the song name, artist name, song duration, location of a sound file (such as an MP3), or any
other information that you might need to associate with a particular file.
The location of an item in an array is called the
index
. All arrays are zero-based, which means
that the first element in the array is [0], the second element is [1], and so on.
There are different kinds of arrays, which you'll discover in the following sections. The most
common arrays use a numerical index to look up a particular item in an
indexed array
. The
second kind of array is called an
associative array
and uses a text index instead of a numerical
index to look up information. For more information on common arrays, see
“About arrays”
on page 163
. For more information on associative arrays, see
“Creating associative arrays”
on page 172
. For more information on multidimensional arrays, see
“Creating
multidimensional arrays” on page 169
. For information on the array access operator, see
“Using dot and array access operators” on page 184
.
The built-in Array class lets you access and manipulate arrays. To create an Array object, you
use the constructor
new Array()
or the array access operator (
[]
). To access the elements of
an array, you also use the array access (
[]
) operator. The next example uses an indexed array.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...