MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 165

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

To use arrays in your code:
1.
Create a new Flash document, and save it as basicArrays.fla.
2.
Add the following ActionScript to Frame 1 of the Timeline:
// define a new array
var myArr:Array = new Array();
// define values at two indexes
myArr[1] = "value1";
myArr[0] = "value0";
// iterate over the items in the array
var i:String;
for (i in myArr) {
// trace the key/value pairs
trace("key: " + i + ", value: " + myArr[i]);
}
In the first line of ActionScript, you define a new array to hold the values. Then, you
define data (
value0
iterate over each of the items in that array and display the key/value pairs in the Output
panel using a trace statement.
3.
Select Control > Test Movie to test your code.
The following text is displayed in the Output panel:
key: 0, value: value0
key: 1, value: value1
For more information on
For information on how to create different kinds of arrays, see the following sections:
"Creating indexed arrays" on page 168
"Creating multidimensional arrays" on page 169
"Creating associative arrays" on page 172
You can find a sample source file, array.fla, in the Samples folder on your hard disk. This
sample illustrates array manipulation using ActionScript. The code in the sample creates an
array and sorts, adds, and removes items of two List components. Find the sample file in the
following directories:
In Windows, browse to boot drive\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\Arrays.
On the Macintosh, browse to Macintosh HD/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/Arrays.
and
) at two indexes of the array. You use a
value1
loops, see
for..in
"Using for..in loops" on page
loop to
for..in
158.
About arrays
165

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

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?

This manual is also suitable for:

Flash 8

Table of Contents