O'Reilly logo

ActionScript: The Definitive Guide by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required