
Chapter 464
In addition, words that are used by ActionScript should never be used as names. Also avoid using
variable names of common programming constructs, even if the Macromedia Flash Player does
not currently support those constructs. This helps to ensure that future versions of the Player will
not conflict with the application. For example, do not use commands such as
MovieClip =
"myMovieClip"
or case = false.
Since ActionScript is based on ECMAScript, application authors can refer to current and future
ECMA specifications to view a list of reserved words. While Flash MX does not enforce the use of
constant variables, authors should still use a naming scheme that indicates the intent of variables.
Variable names should be lower case or mixed case with a lower case first letter, and constant
names should be all upper case. For example:
course_list_output = "foo"; // variable, all lower case
courseListOutput = "foo"; // variable, mixed case
BASEURL = http://www.foo.com; // constant, all upper case
MAXCOUNTLIMIT = 10; // constant, all upper case
MyObject = function(){}; // constructor function
f = new MyObject(); // object
Finally, all SWF files should have names that are lowercase words separated by underscores (for
example, lower_case.swf). This facilitates moving applications to a case-sensitive operating
system, such as UNIX.
Remember that these syntax recommendations are simply guidelines. The most important thing
is to choose a naming scheme and use it consistently.
Commenting your code
Always comment code in an application. Comments are the author’s opportunity to tell a story
about what the code was written to do. Comments should document every decision that was
made while building an application. At each point where a choice was made about how to code
the application, place a comment describing that choice and why it was made.
When writing code that is a work-around for specific issue, make sure you add a comment that
will make the issue clear to future developers who may be looking at the code. This will make it
easier for them to address that issue.
Here is an example of a simple comment for a variable:
var clicks = 0; // variable for number of button clicks
Block comments are useful when a comment contains a large amount of text:
/*
Initialize the clicks variable that keeps track of the number of times
the button has been clicked.
*/
Some common methods for indicating specific topics are:
• // :TODO: topic
Indicates that there is more to do here.
• // :BUG: [bugid] topic
Shows a known issue here. The comment should also explain the issue and give a bug ID if
applicable.
• // :KLUDGE:
Indicates that the following code is not elegant or does not conform to best practices. This
comment alerts others to provide suggestions about how to code it differently next time.
Komentarze do niniejszej Instrukcji