3.5 Primitive Data Versus Composite Data

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 3.  Data and Datatypes

So far we've been working mostly with numbers and strings, which are the most common primitive datatypes. Primitive datatypes are the basic units of a language; each primitive value represents a single datum (as opposed to an array of multiple items) and holds that datum directly, rather than holding its address elsewhere in memory.

ActionScript supports these primitive datatypes: number, string, boolean, undefined, and null. ActionScript does not have a separate single-character datatype (e.g., char) as found in C/C++ (strings are a primitive datatype in ActionScript, and not arrays of chars as they are in C/C++).

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 numbers 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! But if we use an array, we can store our information much more efficiently:

customers = ["Derek", "James", "Joe"];

Now that's nice and tidy. We'll learn much more about composite datatypes in the coming chapters.

     



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net