Object data type

An object is a collection of properties. A property is an attribute that describes the object. For example, the transparency of an object (such as a movie clip) is an attribute that describes its appearance. Therefore, _alpha (transparency) is a property. 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

The ActionScript MovieClip object has methods that let you control movie clip symbol instances on the Stage. This example uses the play() and nextFrame() methods:

mcInstanceName.play();
mc2InstanceName.nextFrame();

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; the number of frames loaded; or the key that the user 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 Example: Writing custom classes.


Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00000646.html