User Guide

ActionScript coding standards 85
Remember, regardless of the version of ActionScript, you should follow good practices. Many of
these practices, such as remaining consistent with case sensitivity, using code completion,
enhancing readability, avoiding keywords for instance names, and keeping a consistent naming
convention, apply to both versions.
If you plan to update your application in future versions of Flash, or make it larger and more
complex, you should use ActionScript 2.0 and classes, to make it easier to update and modify
your application.
ActionScript and Flash Player
If you compile a SWF file that contains ActionScript 2.0 with Publish Settings set to Flash Player
6 and ActionScript 1, code functions as long as it does not use ActionScript 2.0 classes. There is
no case sensitivity or strict data typing involved with the code. However, if you compile your
SWF file with Publish Settings set to Flash Player 7 and ActionScript 1, strict data typing and case
sensitivity are enforced.
ActionScript 2.0 is an improvement to the compiler in the Authoring environment, so you can
target earlier versions of Flash Player while working with ActionScript 2.0.
Writing ActionScript
ActionScript is a case-sensitive language. This means that variables can have the same name,
because slightly different capitalization is considered two separate instances, as the following
ActionScript shows:
var firstName:String = "Jimmy";
trace(firstname); //displays: undefined
In earlier versions of Flash (Flash MX and earlier), Flash would trace the string Jimmy in the
Output panel. Because Flash is case-sensitive,
firstName and firstname are two separate
variables. This is an important concept to understand. If your earlier FLA files have slightly
varying variable capitalization, you might experience unexpected results or broken functionality
when converting the file or application for Flash Player 7.
Note: You should not use two variables that differ only in case. If you are using them as separate
variables, change the instance name, not just the case.
Case sensitivity can have a large impact when working with a web service that uses its own rules
for variable naming and what case variables are in when they are returned to the SWF file from
the server. For example, if you use a Macromedia ColdFusion web service, property names from a
structure or object might be all uppercase, such as
FIRSTNAME. Unless you use the exact same case
in Flash, you are likely to experience unexpected results.
Try to keep ActionScript in a FLA file as generic as possible for the user interface. It is not ideal to
write ActionScript that depends on specific target paths. If the code needs to interact with
interface elements in a larger application, try using a model-view-controller based approach. For
more information, see “Using the MVC design pattern” on page 126.