
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
282
|
Chapter 12: Objects and Classes
Object Classes
Are you ready to get your hands dirty? Let’s create a custom Ball class. The first step
in class creation is designing the properties and methods the class supports. Our Ball
class will have the following properties:
radius Half the diameter of a ball
color A ball’s color
xPosition A ball’s horizontal location
yPosition A ball’s vertical location
Our Ball class will have the following methods:
moveClipTo( ) Used to reposition a ball
getArea( ) Used to determine the amount of space an individual ball occupies
In natural language, our Ball class would be described to the interpreter as follows:
A Ball is a type of object. All ball objects have the properties radius, color, xPosition,
yPosition, which are set individually for each ball. All ball objects also share the
methods moveClipTo( ) and getArea( ), which are identical across all members of the
Ball class.
Instances of our Ball class will have no on-screen presence; for now, they will simply
represent balls conceptually in our program. Later in this chapter, under “Displaying
the Ball on Screen,” we’ll consider how to actually render the ball to screen. Then, in
Chapter 14, we’ll show how to implement our Ball class as a type of movie clip. Stay
tuned!
Making a Class
There is no specific ...