MACROMEDIA FLEX-FLEX ACTIONSCRIPT LANGUAGE Reference page 46

Actionscript language reference
Table of Contents

Advertisement

"Encapsulation" on page 47
"Polymorphism" on page 47
Objects
Think of a real-world object, such as 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 (such as a cat) or a more abstract object
(such as a chemical process).
Note: The word "behaviors" is used generically here and does not refer to the Behaviors
development panel in the Macromedia Flash interface.
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 despite their individual differences, all cats
are members of the same category, or in object-oriented programming terms, the same class: the
class of cats. In object-oriented programming terminology, each individual cat is said to be an
instance of the cat class.
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 jointly referred to as members of that class.
The characteristics (in the cat example; name, age, and color) are called properties of the class and
are represented as variables; the behaviors (eating, sleeping) are called methods of the class and are
represented as functions.
In ActionScript, you define a class with the
on page
51).
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 subclass that extends the Mammal class.
Using subclasses lets you reuse code, so that instead of re-creating all the code common to both
classes you can simply extend an existing class. Another subclass, say, the Siamese class, 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
46
Chapter 2: Creating Custom 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"
55.

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flex

Table of Contents