224
ActionScript language elements
The scope chain used by the
with
statement to resolve identifiers starts with the first item in
the following list and continues to the last item:
■
The object specified in the
object
parameter in the innermost
with
statement.
■
The object specified in the
object
parameter in the outermost
with
statement.
■
The Activation object. (A temporary object that is automatically created when a function
is called that holds the local variables called in the function.)
■
The movie clip that contains the currently executing script.
■
The Global object (built-in objects such as Math and String).
To set a variable inside a
with
statement, you must have declared the variable outside the
with
statement, or you must enter the full path to the Timeline on which you want the variable to
live. If you set a variable in a
with
statement without declaring it, the
with
statement will
look for the value according to the scope chain. If the variable doesn't already exist, the new
value will be set on the Timeline from which the
with
statement was called.
Instead of using
with()
, you can use direct paths. If you find that paths are long and
cumbersome to type, you can create a local variable and store the path in the variable, which
you can then reuse in your code, as shown in the following ActionScript:
var shortcut = this._parent._parent.name_txt; shortcut.text = "Hank";
shortcut.autoSize = true;
Availability:
ActionScript 1.0; Flash Lite 2.0
Parameters
object
:
Object
- An instance of an ActionScript object or movie clip.
Example
The following example sets the
_x
and
_y
properties of the
someOther_mc
instance, and then
instructs
someOther_mc
to go to Frame 3 and stop.
with (someOther_mc) {
_x = 50;
_y = 100;
gotoAndStop(3);
}
The following code snippet shows how to write the preceding code without using a
with
statement.
someOther_mc._x = 50;
someOther_mc._y = 100;
someOther_mc.gotoAndStop(3);
Содержание Flash Lite 2
Страница 1: ...Flash Lite 2 x ActionScript Language Reference...
Страница 22: ...22 Contents...
Страница 244: ...244 ActionScript language elements...
Страница 760: ...760 ActionScript classes...