Chapter 15. Advanced Topics

This chapter collects a variety of advanced ActionScript programming techniques and issues.

Copying, Comparing, and Passing Data

There are three fundamental ways to manipulate data. We may copy it (e.g., assign the value of variable x to variable y), we may compare it (e.g., check whether x equals y), and we may pass it (e.g., supply a variable to a function as an argument). Primitive data values are copied, compared, and passed quite differently than composite data. When primitive data is copied to a variable, that variable gets its own unique and private copy of the data, stored separately in memory. The following lines of code would, hence, cause the string “Dave” to be stored twice in memory, once in the memory space reserved for name1 and again in the space reserved for name2:

name1 = "Dave";
name2 = name1;

We say that primitive data is copied by value because the data’s literal value is stored in the memory space allotted to the variable. In contrast, when composite data is copied to a variable, only a reference to the data (and not the actual data) is stored in the variable’s memory slot. That reference tells the interpreter where the actual data is kept (i.e., its address in memory). When a variable that contains composite data is copied to another variable, it is the reference (often called a pointer) and not the data itself that is copied. Composite data is, hence, said to be copied by reference.

This makes good design sense because it would be ...

Get ActionScript: The Definitive Guide 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.