Chapter 5. Arrays
Introduction
Arrays are essential to successful ActionScript programming.
An array provides a way of grouping related data together, and then organizing and processing that data. The concept of an array should not be foreign to you. In fact, the concept is used all the time in everyday life. You can view a simple grocery list or to-do list as an array. Your address book is an array containing people’s names, addresses, birthdates, and so on. Libraries keep track of books using an indexing system whereby each book becomes, conceptually, an element in a library’s array.
In ActionScript, there are two kinds of arrays: integer-indexed and associative. Both array types group related data, but they use different means of accessing the data.
- Integer-indexed array
Uses integers (numbers) as unique identifiers for each element in the array. Such arrays are ordered by index (i.e., element number), starting from 0. Each element occupies a numbered slot in the array. Integer-indexed arrays are ideal for sets of data that you want to work with in sequential order.
- Associative array
Uses string keys to access each value. You can read more about associative arrays in Recipe 5.15.
Tip
Integer-indexed arrays are the focus of the majority of the recipes in this chapter, and unless otherwise specified, the term “array” refers to an integer-indexed array.
Of course, before you can use an array, you first need to know how to create one. There are two ways to construct a new array in ActionScript: ...
Get ActionScript 3.0 Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.