In this code, you attach a movie clip instance from the library and use the
modify its properties. When you do not specify a variable's scope, you do not always know
where you are setting properties, so your code can be confusing. In the previous code, you
might expect
someVariable
set in a timeline of the SWF file.
It is easier to follow what is happening in your code if you explicitly specify the variables
scope, instead of relying on the
longer, but better, ActionScript example that specifies the variables scope:
this.attachMovie("circleClip", "circle1Clip", 1);
circle1Clip._x = 20;
circle1Clip._y = Math.round(Math.random()*20);
circle1Clip._alpha = 15;
circle1Clip.createTextField("labelTxt", 100, 0, 20, 100, 22);
circle1Clip.labelTxt.text = "Circle 1";
circle1Clip.someVariable = true;
An exception to this rule is, when you are working with the drawing API to draw shapes, you
might have several similar calls to the same methods (such as
the drawing API's functionality. For example, when you draw a simple rectangle, you need
four separate calls to the
this.createEmptyMovieClip("rectangleClip", 1);
with (rectangleClip) {
lineStyle(2, 0x000000, 100);
beginFill(0xFF0000, 100);
moveTo(0, 0);
lineTo(300, 0);
lineTo(300, 200);
lineTo(0, 200);
lineTo(0, 0);
endFill();
}
If you wrote each
lineTo
would quickly become cluttered and difficult to read and debug.
to be set within the
statement. The following example shows a slightly
with
method, as the following code shows:
lineTo
or
method with a fully qualified instance name, the code
curveTo
movie clip, but it is actually
circle1Clip
or
lineTo
ActionScript coding conventions
statement to
with
) because of
curveTo
759
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?