About arrays
169
To create an indexed array:
1.
Create a new Flash document, and save it as
indexArray.fla
.
2.
Add the following ActionScript to Frame 1 of the Timeline:
var myArray:Array = new Array();
myArray.push("one");
myArray.push("two");
myArray.push("three");
trace(myArray); // one,two,three
In the first line of ActionScript, you define a new array to hold the values.
3.
Select Control > Test Movie to test your code.
The following text is displayed in the Output panel:
one,two,three
4.
Return to the authoring tool, and delete the code in the Actions panel.
5.
Add the following ActionScript to Frame 1 of the Timeline:
var myArray:Array = ["one", "two", "three"];
trace(myArray); // one,two,three
In this code you use the array literal to define a new array for your code. This code is the
equivalent of the ActionScript you wrote in step 2. When you test the code, you see the
same output appear in the Output panel.
Creating multidimensional arrays
In ActionScript, you can implement arrays as
nested
arrays
that are essentially arrays of arrays.
Nested arrays, also known as
multidimensional arrays
, can be thought of as matrices or grids.
Therefore, when you are programming, you might use multidimensional arrays to model
these kinds of structures. For example, a chess board is a grid of eight columns and rows; you
could model the chess board as an array that contains eight elements, each of which is also an
array that contains eight elements.
For example, consider a list of tasks that is stored as an indexed array of strings:
var tasks:Array = ["wash dishes", "take out trash"];
If you want to store a separate list of tasks for each day of the week, you can create a
multidimensional array with one element for each day of the week. Each element contains an
indexed array that stores the list of tasks.
CAU
T
IO
N
When you use the array access operator, the ActionScript compiler cannot check
whether the accessed element is a valid property of the object.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...