Principles Of Object-Oriented Programming - MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual

Actionscript reference guide
Hide thumbs Also See for FLASH MX 2004 - ACTIONSCRIPT:
Table of Contents

Advertisement

Principles of object-oriented programming

This section provides a brief introduction to principles involved in developing object-oriented
programs. These principles are described in more depth in the rest of this chapter, along with
details on how they are implemented in Macromedia Flash MX 2004 and Macromedia Flash MX
Professional 2004.
Objects
Think of a real-world object—for example, a cat. A cat could be said to have properties (or states)
such as name, age, and color; a cat also has behaviors such as sleeping, eating, and purring. In the
world of object-oriented programming, objects also have properties and behaviors. Using object-
oriented techniques, you can model a real-world object (like a cat) or a more abstract object (like
a chemical process).
Classes and class members
Continuing with the real-world analogy, consider that there are cats of different colors, ages, and
names, with different ways of eating and purring. But all cats belong to a certain class of object,
an object of type "cat." Each individual (real-world) cat is an instance of the cat class type.
Likewise, in object-oriented programming, a class defines a blueprint for a type of object. The
characteristics and behaviors that belong to a class are referred to as members of that class. The
characteristics (in the cat example, name, age, and color) are called properties of the class, which
are represented as variables; the behaviors (eating, sleeping) are called methods of the class, and are
represented as functions.
For example, you could create a Person class, and then create an individual person that would be
an instance of that class, also called a Person object. The Person object would contain all the
properties and methods of the Person class.
In ActionScript, you define a class with the
on page
161). ActionScript includes a number of built-in classes, such as the MovieClip,
TextField, and String classes. For more information, see
on page
113.
Inheritance
One of the primary benefits of object-oriented programming is that you can create subclasses of a
class; the subclass then inherits all the properties and methods of the superclass. The subclass
typically defines additional methods and properties, or extends the superclass. Subclasses can also
override (provide their own definitions for) methods inherited from a superclass.
For example, you might create a Mammal class that defines certain properties and behaviors
common to all mammals. You could then create a Cat class that extends the Mammal class. In this
way, inheritance can promote code reuse: instead of recreating all the code common to both
classes, you can simply extend an existing class. Another subclass, in turn, could extend the Cat
class, and so on. In a complex application, determining how to structure the hierarchy of your
classes is a large part of the design process.
In ActionScript, you use the
superclass. For more information, see
156
Chapter 9: Creating Classes with ActionScript 2.0
class
keyword to establish inheritance between a class and its
extends
"Creating subclasses" on page
statement (see
"Creating and using classes"
Chapter 6, "Using the Built-In Classes,"
162.

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?

Questions and answers

Table of Contents