Application Development Tips and Tricks > Coding conventions > Following naming guidelines

 

Following naming guidelines

An application's naming scheme must be consistent and names should be chosen for readability. This means that names should be understandable words or phrases. The primary function or purpose of any entity should be obvious from its name. Since ActionScript is a dynamically typed language, the name should also contain a suffix that defines the type of object being referred to by the name. In general, noun-verb and adjective-noun phrases are the most natural choices for names. For example:

Movie name: my_movie.swf

Entity appended to a URL: course_list_output

Component or object: ProductInformation

Variable or property: userName

Function names and variables should begin with a lowercase letter. Objects and object constructors should be capitalized. Using mixed case is also recommended when naming variables, although other formats are acceptable as long as they are used consistently within the application. Variable names can only contain letters, numbers, and underscores. However, do not begin variable names with numbers or underscores.

Examples of illegal variable names:

_count = 5; // begins with an underscore
5count = 0; // begins with a number
foo/bar = true; // contains a forward slash
foo bar = false; // contains a space

In addition, words that are used by ActionScript (reserved words) 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.