
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
246
Chapter 11
CHAPTER 11
Arrays
Back in Chapter 3, we saw that primitive datatypes—strings, numbers, Booleans,
null, and undefined—represent basic information in our scripts. We also saw that
ActionScript supports several composite datatypes, which can group several pieces of
data together into a single datum.
The array type is the first composite datatype we’ll study. Arrays are used to store
and manipulate ordered lists of information and are, therefore, fundamental tools in
sequential, repetitive programming. We use them to do everything from storing val-
ues retrieved via a user-input form, to generating pull-down menus, to keeping track
of enemy spacecraft in a game. In its most basic form, an array is just a list of items,
like your grocery list or the entries in your checkbook ledger.
What Is an Array?
An array is a data structure that can encompass multiple individual data values, just
like a building is a physical structure encompassing multiple floors. Unlike a primi-
tive datatype, an array can include more than one data value. Here is a simple exam-
ple showing two separate strings, followed by an array that contains two strings:
"oranges" // A single primitive string value
"apples" // Another primitive string value
["oranges", "apples"] // A single array containing two strings ...