
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Classes and Object-Oriented Programming
|
281
numbered array elements, with a for-in loop used to access an object’s properties.
For more information on for-in loops, including how to prevent an object’s proper-
ties from being exposed to for-in, see Chapter 8.
Object Methods
Methods are functions that are associated with objects and are typically used to per-
form an object-related task or access an object’s data (i.e., set and retrieve its proper-
ties). We invoke methods with the function call operator,
(), using the dot operator
to separate the method name from its object:
objectName.methodName()
For example:
ball.getArea( ); // Call the getArea( ) method of ball
As with properties, methods are defined by a class and then used with individual
object instances. For example, the MovieClip class defines a play( ) method that we
use on a particular movie clip instance (such as the main timeline of a movie):
_root.play( );
Methods can take parameters, return values, and otherwise behave exactly like
functions, with the added feature that they can access and operate on the object
through which they are invoked. For example, here we invoke gotoAndPlay( ) as a
method of the
_root movie clip object, passing the destination frame number, 5, as
an argument:
_root.gotoAndPlay(5);
And here we invoke the ...