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 class’s
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");
}
}
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...