User Guide

78 Chapter 3: Using Best Practices
Note: If you place the comment characters (/* and */) on separate lines at the beginning and end of
the comment, you can easily comment them out by placing double slash characters (//) in front of
them (for example, ///* and //*/). This lets you quickly and easily comment and uncomment your
code.
Use the following format for single-line comments:
// the following sets a local variable for age
var myAge:Number = 26;
The following single-line comment is formatted as a trailing comment, which is on the same line
as the ActionScript:
var myAge:Number = 26; //variable for my age
If you use the Auto Format feature with your code, trailing comments move to the next line. Add
these comments after you format your code, or you must modify their placement after using Auto
Format.
Sometimes you must distinguish important comments when writing code. The following
conventions demonstrate some of the common methodologies that programmers use.
When more code needs to be added to a section, you can use the following format:
// :TODO: comment
Use the following format when there is a known issue with your code or application, or there is
another problem. Note a bugs ID or number, if possible. Adding a bug ID helps prevent
recurring problems and saves time.
// :BUG: [bug id] comment
When ActionScript needs further modifications because it is inelegant or does not follow best
practices, use the following format:
// :KLUDGE:
When ActionScript is intricately designed and interacts with other areas of an application, use the
following format to alert developers who might work on the code later:
// :TRICKY:
These practices help Flash users who learn from the commented source code. Another benefit of
using these methodologies is that you can easily locate bugs and unfinished items by using the
Find tool in the Actions panel.
Note: For readability, single-line comments (// ) are often used instead of block comments. This
increases the readability of the code for instructional purposes.
For information on using comments in classes, see “Using comments in classes” on page 102.
Using code completion and suffixes
Use strict data typing with your variables whenever possible because it helps you in the following
ways:
Adds code completion functionality, which speeds up coding.
Helps you avoid errors in your compiled SWF files.