Then create a new class called Socks that extends the Clothes class, as shown in the following
example:
class Socks extends Clothes {
private var color:String;
function Socks(param_color:String) {
this.color = param_color;
trace("[Socks] I am the constructor");
}
function getColor():String {
trace("[Socks] I am getColor");
return super.getColor();
}
function setColor(param_color:String):Void {
this.color = param_color;
trace("[Socks] I am setColor");
}
}
Then create a new AS or FLA file and enter the following ActionScript in the document:
import Socks;
var mySock:Socks = new Socks("maroon");
trace(" -> "+mySock.getColor());
mySock.setColor("Orange");
trace(" -> "+mySock.getColor());
The following result is written to the log file:
[Clothes] I am the constructor
[Socks] I am the constructor
[Socks] I am getColor
[Clothes] I am getColor
-> maroon
[Socks] I am setColor
[Socks] I am getColor
[Clothes] I am getColor
-> Orange
If you forgot to put the
method could call itself repeatedly, which would cause the script to fail because of
getColor()
infinite recursion problems. The log file would display the following error if you didn't use the
keyword:
super
[Socks] I am getColor
[Socks] I am getColor
...
[Socks] I am getColor
256 levels of recursion were exceeded in one action list.
This is probably an infinite loop.
Further execution of actions has been disabled in this movie.
210
Chapter 5: ActionScript Core Language Elements
keyword in the Sock class's
super
method, then the
getColor()
Need help?
Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?