A array is an object used to hold organized data. Arrays are similar to variables in the way they hold data, the only difference being that a varaible can only hold one piece of data whereas an array can hold more than one piece of data. Each piece of data in an array is called an element and is refered to by an index.The first element is refered to by the index [0] the second element [1] and so on.
To create an array you must use the "New Array" constructor.
name_of_array = New Array();
To enter data into an array you must allocat each piece of data to a specific element using the index notation.
name_of_array[0] = "value1";
name_of_array[1] = "value2";
name_of_array[2] = "value3";
Another way to create an array of values to declare the values of each required element inline with the constructor.
name_of_array = New Array ("value1","value2","value3");
This method is the same as the first the only difference is the syntax "the way it is written" as far as flash is concerned the two actionscript statements are identicle.
Note: Arrays can also be used to store mulltiple pieces of
information in each element. e.g
var 2d_coordinates:Array = new Array();
2d_coordinates[0] = {x:160,y:100};
2d_coordinates[1] = {x:240,y:100};
2d_coordinates[2] = {x:100,y:150};
2d_coordinates[3] = {x:300,y:150};
2d_coordinates[4] = {x:160,y:200};
2d_coordinates[5] = {x:240,y:200};
To reference a specific dataq within an element
reference the array element then type a dot and the
name of the variable in the element. e.g.
my_mc_x = 2d coordinates [2].x;
my_mc_y = 2d_coordinates[2].y;
This is can be used to neatly
store 2d coordinates [Attaching
Multiple Movie Clips In A Set Position]
or can be expanded to include
3d coordinate points and movie clip properties. |