MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 311

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

8.
In Dog.as, type the following ActionScript code into the Script window:
class Dog extends Mammal {
// constructor
public function Dog(gender:String) {
super(gender);
speciesName = "Dog";
}
public function play():String {
return "Fetch a stick.";
}
}
Notice that the Dog class is very similar in structure to the Cat class, except that a few of
the values have changed. Again, the Dog class extends the Mammal class and inherits all
its methods and properties. The Dog constructor takes a single property, gender, which it
passes to the Dog class's parent class, Mammal. The
overridden and set to the string
parent class.
9.
Save your changes to the ActionScript document.
10.
Create another ActionScript document in the same directory as your other files, and save
it as Monkey.as.
11.
In Monkey.as, type the following ActionScript code into the Script window:
class Monkey extends Mammal {
// constructor
public function Monkey(gender:String) {
super(gender);
speciesName = "Monkey";
}
public function play():String {
return "Swing from a tree.";
}
}
Similar to the previous two classes, Cat and Dog, the Monkey class extends the Mammal
class. The Monkey class's constructor calls the constructor for the Mammal class, passing
the gender to the Mammal's constructor, as well as setting
. The Monkey class also overrides the behavior of the
Monkey
12.
Save your changes to the ActionScript document.
13.
Now that you've created three subclasses of the Mammal class, create a new Flash
document called mammalTest.fla.
speciesName
. The
method is also overridden from the
Dog
play()
Using polymorphism in an application
variable is also
to the string
speciesName
method.
play()
311

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

This manual is also suitable for:

Flash 8

Table of Contents