EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - About Writing Subclasses in Flash

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
About writing subclasses in Flash 303
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 or static classes,
such as the Math, Key, and Mouse classes.
To create this kind of relationship between two classes, you use the class statements
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:
About writing a subclass” on page 303
“Overriding methods and properties” on page 306
For more information on private members, see About public, private, and static methods and
properties (members)” on page 247. For an example that creates a subclass, see “Example:
Extending the Widget class” on page 304.
About writing a subclass
The following code defines the custom class JukeBox, which extends the Sound class. It
defines an array called
song_arr and a method called playSong(), which plays a song and
invokes the
loadSound() method that it inherits from the Sound class.
class JukeBox extends Sound {
public var song_arr:Array = new Array("beethoven.mp3", "bach.mp3",
"mozart.mp3");
public function playSong(songID:Number):Void {
super.loadSound(song_arr[songID], true);
}
}

Table of Contents

Related product manuals