EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 185

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
About operators 185
4. Add the following ActionScript to Frame 1 of the Timeline:
myClip.spam = 5;
trace(myClip.spam); // 5
If you want to set a value in the myClip instance on the current timeline you can use the
dot or array access operators, as demonstrated in this ActionScript. If you write an
expression inside the array access operator, it evaluates that expression first and uses the
result as the variable name.
5. Select Control > Test Movie to test the document.
The Output panel displays 5.
6. Return to the authoring environment, and replace the first line of ActionScript with
the following:
myClip["spam"] = 10;
7.
Select Control > Test Movie to test the document.
The Output panel displays 10.
8. Return to the authoring environment, and double-click the myClip instance.
9. Add four new instances inside the myClip instance.
10. Use the Property inspector to add the following instance names to each of the four new
instances: nestedClip1, nestedClip2, nestedClip3, nestedClip4.
11. Add the following code to Frame 1 of the main Timeline:
var i:Number;
for (i = 1; i <= 4; i++) {
myClip["nestedClip" + i]._visible = false;
}
This ActionScript toggles the visibility of each of the nested movie clips.
12. Select Control > Test Movie to test the ActionScript you just added.
Now the four nested instances are invisible. Youre using the array access operator to
iterate over each nested movie clip in the myClip instance and set its visible property
dynamically. You save time, because you dont have to specifically target each instance.
You can also use the array access operator on the left side of an assignment, which lets you set
instance, variable, and object names dynamically:
myNum[i] = 10;
In ActionScript 2.0, you can use the bracket operator to access properties on an object that are
created dynamically, in case the class definition for that object is not given the
dynamic
attribute. You can also create multidimensional arrays using this operator. For more
information on creating multidimensional arrays using array access operators, see “Creating
multidimensional arrays” on page 169.

Table of Contents

Related product manuals