25 July 2010
In Adobe Flash Platform content development, a base class is the ActionScript class that other classes use for a primary set of properties and methods.
For symbols in Adobe Flash Professional, the value of the base class defaults to flash.display.MovieClip. For scripting a custom ActionScript class in Flash Professional or Adobe Flash Builder, the value of the base class defaults to flash.display.Sprite. Use these defaults unless you are using an automatically generated class that uses the functionality of an external class. Base class is not synonymous with extension; if you are specifying a custom class that itself extends another class, it is not necessary to specify this superclass as the base class. In this situation, the default of flash.display.MovieClip is sufficient.
However, if you wanted two symbols named GreenCar and BlueCar to function identically but use different skins, you could use the drawing tools to create different appearances, then set their base class to Car and use a Car class in an external Car.as file to provide the functionality for both cars.
When making a custom class, create an external file with the structure of an automatically generated class, and then add the appropriate properties and methods to the class.
Inheritance is a form of code reuse that allows programmers to develop new classes that are based on existing classes. The existing classes are often called base classes or superclasses, while the new classes are called subclasses. A key advantage of inheritance is that it allows you to reuse code from a base class yet leave the existing code unmodified.
Additionally, inheritance requires no changes to the way that other classes interact with the base class. Rather than modifying an existing class that may have been thoroughly tested or may already be in use, using inheritance you can treat that class as an integrated module that you can extend with additional properties or methods. You use the
extends keyword to indicate that a class inherits from another class.
Below is an overview of the DisplayObject class in the ActionScript 3 Reference for the Adobe Flash Platform:
The DisplayObject documentation shows that it uses the EventDispatcher class as its base class, and also that several classes (listed as "subclasses") use DisplayObject as their base class. Because the DisplayObject class inherits methods and properties from the EventDispatcher class, and the EventDispatcher class uses the Object class as its base class, the DisplayObject class also inherits properties and methods from the Object class through the inheritance chain.
Inheritance also allows you to take advantage of polymorphism in your code. Polymorphism is the ability to use a single method name for a method that behaves differently when applied to different data types. A simple example is a base class named Shape with two subclasses named Circle and Square. The Shape class defines a method named
area(), which returns the area of the shape. If polymorphism is implemented, you can call the
area() method on objects of type Circle and Square and have the correct calculations done for you. Inheritance enables polymorphism by allowing subclasses to inherit and redefine, or override, methods from the base class.