
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Object Properties
|
279
example, the following code creates a new Date object and stores a reference to it in
the variable named
now:
var now = new Date( );
A specific time is a complex set of numbers that includes a second, minute, hour,
day, month, and year. Using a Date object’s methods, we can easily check or set any
aspect of the time represented by the object. For example, we can invoke the
getHours( ) method to check the hour (in 24-hour format), as follows:
trace("The current hour is: " + now.getHours( ));
Let’s take a closer look at how to use an object’s properties and methods before
showing how to add them to our own custom classes.
Object Properties
As you learned earlier, properties are named data containers associated with an
object. They are defined once by an object’s class but set individually for each object
instance. Like variables, object properties can contain any kind of data—strings,
numbers, Booleans,
null, undefined, functions, arrays, movie clips, or even other
objects.
Referring to Properties
The familiar dot operator gives us access to an object’s properties. We separate the
name of the property from the object it belongs to using a dot (a period), as follows:
objectName.propertyName
where objectName is the name of our object and propertyName must be a legal identi- ...