User Guide
ActionScript coding standards 87
Using trace statements
Use
trace statements in your documents to help you debug your code while authoring the FLA
file. For example, by using a
trace statement and for loop, you can see the values of variables in
the Output panel, such as strings, arrays, and objects, as the following example shows:
var day_array:Array = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
var numOfDays:Number = day_array.length;
for (var i = 0; i<numOfDays; i++) {
trace(i+": "+day_array[i]);
}
This displays the following information in the Output panel:
0: sun
1: mon
2: tue
3: wed
4: thu
5: fri
6: sat
Using a trace statement is an efficient way to debug your ActionScript.
You can remove your
trace statements when you publish a SWF file, which makes minor
improvements to playback performance. Before publishing a SWF file, open Publish Settings and
select Omit Trace Actions on the Flash tab. For more information on using trace, see
trace() in
Flash ActionScript Language Reference.
Using 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 demonstrates the use of
proper scoping using the
super prefix:
// readable
var pelican = super.bird;
var animal = super.super.bird;
The following ActionScript is not as readable. Avoid using the following syntax because it does
not reveal from where you invoke the method:
// not readable
var pelican = bird; // scoped to super.bird
var animal = super.super.bird;
Avoiding the with statement
One of the more confusing concepts for people learning ActionScript to understand is using the
with statement. Consider the following code that uses the with statement:
this.attachMovie("circle_mc", "circle1_mc", 1);
with (circle1_mc) {
_x = 20;
_y = Math.round(Math.random()*20);
_alpha = 15;