758 Best Practices and Coding Conventions for ActionScript 2.0
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 displayed in the Output panel:
[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 super keyword in the Socks class's getColor() method, the
getColor() method could call itself repeatedly, which would cause the script to fail because
of infinite recursion problems. The Output panel would display the following error if you
didn't use the super keyword:
[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 SWF file.
Avoid the with statement
One of the more confusing concepts to understand for people learning ActionScript 2.0 is
using the
with statement. Consider the following code that uses the with statement:
this.attachMovie("circleClip", "circle1Clip", 1);
with (circle1Clip) {
_x = 20;
_y = Math.round(Math.random()*20);
_alpha = 15;
createTextField("labelTxt", 100, 0, 20, 100, 22);
labelTxt.text = "Circle 1";
someVariable = true;
}