The previous class defines two private variables,
store the animal's gender and mammal type. Next, the
constructor takes a single parameter,
variable defined earlier. Three additional public methods are also specified:
, and
play()
sleep()
getter and setter methods for the mammal's
3.
Save the ActionScript document.
This class serves as the superclass for the Cat, Dog, and Monkey classes, which you create
shortly. You can use the
representation of any Mammal instance (or any instance that extended the
Mammal class).
4.
Create a new ActionScript file and save it as Cat.as in the same directory as the Mammal.as
class file you created in step 1.
5.
In Cat.as, type the following ActionScript code into the Script window:
class Cat extends Mammal {
// constructor
public function Cat(gender:String) {
super(gender);
speciesName = "Cat";
}
public function play():String {
return "Pounce a ball of yarn.";
}
}
Notice that you are overriding the
class defines only two methods, a constructor and a
extends the Mammal class, the Mammal classes's methods and properties are inherited by
the Cat class. For more information on overriding, see
properties" on page
6.
Save your changes to the ActionScript document.
7.
Create a new ActionScript document and save it as Dog.as in the same directory as the two
previous class files.
310
Inheritance
gender
, each of which returns string objects. The final three methods are
method of the Mammal class to display a string
toString()
play()
306.
and
_gender
_name
constructor is defined. The
Mammal
, which it uses to set the private
and
_gender
_name
method in the Mammal superclass. The Cat
method. Since the Cat class
play()
"Overriding methods and
, which are used to
_gender
toString(),
properties.
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?