In this chapter, you'll look at arrays. Arrays contain indexed data, like a numbered list of items. By using an array, you can store multiple pieces of data in a single variable, which allows you to group values that should go together. An array also provides methods and properties that let you edit it, search through it, sort it, and operate on its contents. Arrays are key tools in any programmer's toolbox.
Arrays are the first complex data type that you study in Part II, "Core ActionScript 3.0 Data Types." Strings, numbers, Booleans, and the like are all primitive data types—the core building blocks of information that usually contain a single piece of data of a specific type. Complex data types, on the other hand, are composites of the various primitive types.
Arrays are a lot like a numbered list of items. Each item, or element, in an array has a location, or index. Unlike most numbered lists, indices in an array start at 0 instead of 1. These indices are used to look up elements in the array, as shown in Figure 8-1.
Let's create the first array and fill it with information. For this, you're going to use the
var myArray:Array = new Array();
Remember that a constructor is a function that creates an instance of a class. A constructor is always named after the class it constructs. To use a constructor, use the
new keyword followed by the constructor name—for example,
Figure 8.1. To ...