TIP
Typically, all instances of an object class share the same methods
and property names; it is the property values of
each instance that distinguish it from other instances of the same
class.
Whether we create objects ourselves or use those built into
ActionScript, OOP keeps the components of a program cleanly separated
from one another (encapsulated ) and allows them
to interoperate without knowing the details of other objects. This
allows an object to change its internal functionality without
adversely affecting other portions of the program that rely on the
object, so long as the object's methods (i.e., its interfaces
to the outside world) don't change. Returning to our
ball object, for example, we don't care if
the laws of physics change the behavior of our ball's motion.
We just call the ball's move( ) method and
let the object itself worry about the details.
Another nice feature of OOP is that we can treat
different objects that have
different behaviors in a uniform manner as long
as they implement methods of the same name. For example, suppose we
have a circle object and a
square object. As long as both objects implement
an area( ) method that returns the shape's
area, we can call their area( ) methods without
worrying about how each object calculates its own area.
In this chapter, we'll learn how to make a basic object, and
we'll learn how to define a category of objects (i.e., a
class). Once we're comfortable with the basics, we'll see
how to share common characteristics between classes and objects
(i.e., create a family tree) using inheritance.
For example, we might implement a Horse class
that along with our Dog class are descendants of
the Mammal class. The
Mammal class could implement methods and
properties common to all mammals, such as the fact that they have
hair, give milk, and are warm-blooded. Finally, we'll learn how
OOP is used to control the Flash environment through
ActionScript's built-in objects and classes.