Brief Introduction to OOP
Object-oriented programming (OOP) is sometimes
shrouded in mystery and mysticism. You might have
phrases such as "the zen of OOP." But when you get right down to
it, OOP is just a way of organizing code. I'd even go so far as to
say that it's the best way to organize complex or large
Chapter 11, "Introducing ActionScript," covered
simple datatypes in Flash.
are containers, and datatypes
are a way to say what kind of data can be stored in that container.
A variable with a number datatype holds a number, a string holds a
, and an array holds a list of strings,
, or objects.
Each datatype has certain properties and methods
unique to its type. For example, a number can hold numerical values
and have mathematical
applied to it. A class defines a
When we start discussing objects, things start
getting more interesting. An object can hold properties, which are
simply variables of a datatype (the object container holds the
variable container). Objects can also hold another complex datatype
. In Chapter 11,
functions were defined as encapsulated segments of code with a
single set of functionality. They are "run" when called by
another section of code. When functions are stored in an object,
they are called
So how do you organize code differently when you
work with ActionScript 2.0 and object-oriented programming in
Flash? When Chapter 11 introduced ActionScripting, you learned to
look at variables and functions as ways to organize your code. Now
you're ready to move to a more sophisticated organizational
structure where all of your code is stored in objects, which are
simply containers of containers.
However, before you can create an instance of an
object, you must have a class. A
describes an object as well as what
properties and methods belong to that object. It can be one of the
built-in classes, such as Math, or a custom class that you write
yourself. In either case, a class is a datatype that describes all
the properties and methods that are available to be applied to an
object created from the class description.
You can think of a class as the blueprint for an
object. Just as many
from the same set
of blueprints, multiple objects can be described by a single class.
It is important to understand that
datatypes and objects in Flash are
object, and even the
object are all based on classes that are built into
Flash. For a complete list of all built-in datatypes (classes)
available to you in Flash, go to the Action panel and choose Types
from the left Action listing.