EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 757

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...
ActionScript coding conventions 757
About the super prefix
If you refer to a method in the parent class, prefix the method with super so that other
developers know from where the method is invoked. The following ActionScript 2.0 snippet
demonstrates the use of proper scoping by using the
super prefix:
In the following example, you create two classes. You use the
super keyword in the Socks class
to call functions in the parent class (Clothes). Although both the Socks and Clothes classes
have a method called
getColor(), using super lets you specifically reference the base classs
methods and properties. Create a new AS file called Clothes.as, and enter the following code:
class Clothes {
private var color:String;
function Clothes(paramColor) {
this.color = paramColor;
trace("[Clothes] I am the constructor");
}
function getColor():String {
trace("[Clothes] I am getColor");
return this.color;
}
function setColor(paramColor:String):Void {
this.color = paramColor;
trace("[Clothes] I am setColor");
}
}
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(paramColor:String) {
this.color = paramColor;
trace("[Socks] I am the constructor");
}
function getColor():String {
trace("[Socks] I am getColor");
return super.getColor();
}
function setColor(paramColor:String):Void {
this.color = paramColor;
trace("[Socks] I am setColor");
}
}

Table of Contents

Related product manuals