You can declare the data type of objects based on built-in classes (Button, Date, MovieClip,
and so on) and on classes and interfaces that you create. In the following snippet, you create a
new object of the custom type Student:
var firstStudent:Student = new Student();
You can also specify that objects are of the Function or the Void data type. For more
information on assigning data types, see
Curly braces
You group ActionScript events, class definitions, and functions into blocks using curly brace
(
) punctuators. You put the opening brace on the same line as the declaration.
{}
You can also put the opening brace on the line that follows the declaration. Coding
conventions recommend that you put the opening brace on the same line for
consistency. For information on braces and code conventions, see
Practices and Coding Conventions for ActionScript 2.0," on page
Place braces around each statement when it is part of a control structure (such as
), even if it contains only a single statement. This good practice helps you avoid errors in
for
your ActionScript when you forget to add braces to your code. The following example shows
code that is written using poor form:
var numUsers:Number;
if (numUsers == 0)
trace("no users found.");
Although this code validates, it is considered poor form because it lacks braces around
the statements.
Braces are added to this statement if you click the Check Syntax button.
In this case, if you add a second statement after the trace statement, the second statement
executes regardless of whether the
results. For this reason, add braces so the code looks like the following example:
var numUsers:Number;
if (numUsers == 0) {
trace("no users found");
}
126
Syntax and Language Fundamentals
Chapter 4, "Data and Data Types," on page
variable equals 0, which can lead to unexpected
numUsers
71.
Chapter 19, "Best
731.
or
if..else
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?