ActionScript coding conventions 747
However, placing the equivalent ActionScript code on a timeline appears as follows:
// good code
myBtn.onRelease = function() {
// Do something.
};
For more information on ActionScript syntax, see “Formatting ActionScript syntax”
on page 764.
Handling scope
Scope is the area where the variable is known and can be used in a SWF file, such as on a
timeline, globally across an application, or locally within a function. Typically, you can
reference scope in more than one way when you write code. Using scope correctly means that
you can create portable and reusable ActionScript code, and you don’t risk breaking your
applications as you build new modules.
It is important to understand the difference between the global and root scopes. The root
scope is unique for each loaded SWF file. The global scope applies to all timelines and scopes
within SWF files. You use relative addressing rather than references to root timelines, because
relative addressing makes your code reusable and portable. For more information on handling
scope in your applications, see the following sections:
“About variables and scope” on page 96
“About scope and targeting” on page 123
“Understanding classes and scope” on page 283.
NOTE
Using behaviors and screens sometimes involves attaching code to objects, so different
practices apply when you use these features. For more information, see Chapter 3,
“Best practices for using behaviors” in Using Flash.