736
Best Practices and Coding Conventions for ActionScript 2.0
Naming variables
Variable names can only contain letters, numbers, and dollar signs (
$
). Do not begin variable
names with numbers. Variables must be unique and they are case-sensitive in Flash Player 7
and later. For example, avoid the following variable names:
my/warthog = true; // includes a slash
my warthogs = true; // includes a space
my.warthogs = true; // includes a dot
5warthogs = 55; // begins with a number
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.
■
Generates errors in the Output panel so you don’t have a silent failure when you compile
your SWF file. These errors help you find and fix problems in your applications.
To add a data type to your variables, you must define the variable using the
var
keyword. In
the following example, when creating a LoadVars object, you would use strict data typing:
var paramsLv:LoadVars = new LoadVars();
Strict data typing provides you with code completion, and ensures that the value of
paramsLv
contains a LoadVars object. It also ensures that the LoadVars object will not be used to store
numeric or string data. Because strict typing relies on the
var
keyword, you cannot add strict
data typing to global variables or properties within an object or array. For more information
on strict typing variables, see
“About assigning data types and strict data typing” on page 81
.
Use the following guidelines when you name variables in your code:
■
All variables must have unique names.
■
Don’t use the same variable name with different cases.
Don’t use, for example,
firstname
and
firstName
as different variables in your
application. Although names are case-sensitive in Flash Player 7 and later, using the same
variable name with a different case can be confusing to programmers reading your code
and can cause problems in earlier versions of Flash that do not force case sensitivity.
■
Don’t use words that are part of the ActionScript 1.0 or 2.0 language as variable names.
In particular, never use keywords as instance names, because they cause errors in your
code. Don’t rely on case sensitivity to avoid conflicts and get your code to work.
NO
TE
Strict data typing does not slow down a SWF file. Type checking occurs at compile time
(when the SWF file is created), not at runtime.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...