MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 758

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

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
method could call itself repeatedly, which would cause the script to fail because
getColor()
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
statement. Consider the following code that uses the
with
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;
}
758
Best Practices and Coding Conventions for ActionScript 2.0
keyword in the Socks class's
super
method, the
getColor()
statement:
with

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

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?

This manual is also suitable for:

Flash 8

Table of Contents