
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Variable Scope
|
49
In traditional programming, variables are often broken into two general scope cate-
gories: global and local. Variables that are accessible throughout an entire program
are called global variables. Variables that are accessible only to limited sections of a
program are called local variables. In addition to these two conventional variable
types, Flash adds timeline variables that are scoped to individual movie clip
instances. Flash 5 supported conventional local variables but did not support true
global variables; Flash MX introduces support for true global variables.
In Flash, all variables are scoped to one of the following:
• A function (local variable)
• The main timeline or a movie clip (timeline variable)
• In Flash MX, the
_global object (global variable)
Movie Clip Variables and Global Variables
As shown in the two earlier scenarios, a variable defined on a timeline is available to
all the scripts on that timeline—from the first frame to the last frame. But what hap-
pens if we have more than one timeline in a movie, as described in Scenario 3?
Scenario 3: Variables declared on separate timelines
Suppose we have two basic geometric shapes, a square and a circle, defined as movie
clip symbols. Recall that each movie clip maintains its own independent timeline.