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

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

For example, you might start with a class called Mammal that has
methods. You then create Cat, Monkey, and Dog subclasses to extend the Mammal class. The
subclasses override the
particular kinds of animals. Monkey implements the
implements the
play()
method to fetch a ball. Because the
would use the superclass implementation. The following procedure demonstrates this
example in Flash.
To use polymorphism in an application:
1.
Create a new ActionScript document and save it as Mammal.as.
This document is the base class for a few different animal classes that you create in
upcoming steps.
2.
In Mammal.as, type the following ActionScript code into the Script window:
class Mammal {
private var _gender:String;
private var _name:String = "Mammal";
// constructor
public function Mammal(gender:String) {
this._gender = gender;
}
public function toString():String {
return "[object " + speciesName + "]";
}
public function play():String {
return "Chase another of my kind.";
}
public function sleep():String {
return "Close eyes.";
}
public function get gender():String {
return this._gender;
}
public function get speciesName():String {
return this._name;
}
public function set speciesName(value:String):Void {
this._name = value;
}
}
method from the Mammal class to reflect the habits of those
play()
method to pounce at a ball of yarn; Dog implements the
sleep()
method to swing from trees; Cat
play()
functionality is similar among the animals, you
Using polymorphism in an application
and
play()
sleep()
play()
309

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?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents