User Guide
About data types 21
Object data type
An object is a collection of properties. Each property has a name and a value. The value of a
property can be any Flash data type—even the object data type. This lets you arrange objects
inside each other, or nest them. To specify objects and their properties, you use the dot (
.)
operator. For example, in the following code,
hoursWorked is a property of weeklyStats, which
is a property of
employee:
employee.weeklyStats.hoursWorked
You can also create custom objects to organize information in your Flash application. To add
interactivity to an application with ActionScript, you need many pieces of information: for
example, you might need a user’s name, age, and phone number; the speed of a ball; the names of
items in a shopping cart; or the key that was pressed last. Creating custom objects lets you
organize this information into groups, simplify your scripting, and reuse your scripts.
The following ActionScript code shows an example of using custom objects to organize
information. It creates a new object called
user and creates three properties: name, age and phone
which are String and Numeric data types.
var user:Object = new Object();
user.name = "Irving";
user.age = 32;
user.phone = "555-1234";
For more information, see “Using classes: a simple example” on page 48.
MovieClip data type
Movie clips are symbols that can play animation in a Flash application. They are the only data
type that refers to a graphic element. The MovieClip data type lets you control movie clip
symbols using the methods of the MovieClip class.
You do not use a constructor to call the methods of the MovieClip class. You can create a movie
clip instance on the Stage or create an instance dynamically. Then you simply call the methods of
the MovieClip class using the dot (
.) operator.
Working with movie clips on the Stage. The following example calls the startDrag() and
getURL() methods for different movie clip instances that are on the Stage:
my_mc.startDrag(true);
parent_mc.getURL("http://www.macromedia.com/support/" + product);
The second example returns the width of a movie clip called my_mc on the Stage. The targeted
instance must be a movie clip, and the returned value must be a numeric value.
function getMCWidth(target_mc:MovieClip):Number {
return target_mc._width;
}
trace(getMCWidth(my_mc));