Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Inheritance > About writing subclasses in Flash | |||
In object-oriented programming, a subclass can inherit the properties and methods of another class, called the superclass. You can extend your own custom classes as well as many of the core and Flash Player ActionScript classes. You cannot extend the TextField class.
To create this kind of relationship between two classes, you use the class statement's extends clause. To specify a superclass, you use the following syntax:
class SubClass extends SuperClass {}
The class you specify in SubClass inherits all the properties and methods defined in SuperClass.
For example, you might create a Mammal class that defines properties and methods common to all mammals. To create a variation of the Mammal class, such as a Marsupial class, you would extend the Mammal class--that is, create a subclass of the Mammal class, as follows:
class Marsupial extends Mammal {}
The subclass inherits all the properties and methods of the superclass, including any properties or methods that you have declared to be private using the private keyword.
For more information on extending classes, see the following topics:
For more information on private members, see About public, private, and static methods and properties (members). For an example that creates a subclass, see Example: Extending the Widget class.
Flash CS3