This content has been marked as final. Show 2 replies
Star Tail Pro,
> I would like to know what a subclass is and how to
> use them. I've heard of inheritance but how does it
> work. How do subclasses work.
Subclasses are classes that inherit from a base class. First, what's a
class? A class is a collection of code that defines an object. The
MovieClip class, for example, defines what every movie clip symbol in Flash
can do (its methods), what it can react to (its events), and what
characteristics it has (its properites). The TextField class defines all of
the above for dynamic and input text fields. The Array class defines the
above for arrays, and so on.
When a subclass class inherits a base class, it becomes everything that
base class is, plus whatever else you program it to do. You might, for
example, write your own class called Vehicle. Every Vehicle instance (that
is, every vehicle object) in your code is going to share certain
characteristics. All vehicles move, so they're all going to have a
Vehicle.move() method. All vehicles have a speed, so they're all going to
have a Vehicle.speed property. Now, a car is going to have certain features
*in addition* to the general Vehicle features. A car *is* a vehicle, so it
can inherit the Vehicle base class, which makes it a vehicle. But in
addition, it has car-specific features that you will define in your Car
Check out the excellent three-part ActionScript 2.0 Primer on Joey
Lott's website, here ...
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."
In general: a toplevel object might be Shape and it contains properties and methods that are shared by all Shapes. A subclass of Shape is Circle or Square and they contain properties and methods that are specific to their shape. So, in a toplevel class you describe all general functionality and each subclass adds specific functionality. The objective is to be able to reuse (and maintain) the basic code and scalability: you can add objects easily.