
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
74
|
Chapter 3: Data and Datatypes
Primitive datatypes are, as their name suggests, simple. They can hold text messages,
frame numbers, secret passwords, and so on, but they don’t readily accommodate
higher levels of complexity. For more elaborate data handling—such as simulating
the physics of a dozen bouncing balls or managing a quiz with 500 questions and
answers—we turn to composite datatypes. Using composite data, we can manage
multiple pieces of related data as a single datum.
ActionScript supports the following composite datatypes: array, object, and movieclip.
Technically, functions are a type of object and are therefore considered composite
data, but we rarely manipulate them as such. See Chapter 9 for more about functions
as a datatype.
Whereas a single number is a primitive datum, a list (i.e., an array) of multiple num-
bers is a composite datum. Here’s a practical example of how composite datatypes
are useful: suppose we want to store the name of a customer named Derek. We can
create a variable that stores Derek’s name as a primitive value, like this:
var custName = "Derek";
However, this approach gets pretty cumbersome once we add more customers.
We’re forced to use sequentially named variables to keep track of our customers—
cust1Name, cust2Name, cust3Name, and so on. Yuck! ...