Tutorial details:
Written by: Guy Watson aka. FlashGuru
Difficulty Level: Intermediate
Requirements: Flash 5 and above.

If you are interested in arrays then i assume you already know about variables. Variables are a container for one piece of data, this piece of data can be a number, a string or a boolean value.  See the associated tutorial.

Arrays are similar to variables as they too are containers for data, except that they can hold more than one piece of data, each element(piece of data) is referred to by an index.

Arrays can be used to keep your scripts more organised, they are usually used to group together multiple values that are in some way related to each other, the values use an index to distinguish them from each other. Suppose you wanted to write out 3 quotes for use in your movie and use variables for each quote, you could define 3 variables as follows:

quote1 = "Flash is cool!";
quote2 = "Flash is my favourite program";
quote3 = "Flash rules";

However a better way may be to use an array, there are numerous ways of creating an array but i will show you the easiest way first:

name_of_array = new Array();

So to store our quotes in an array we could use:

quotes = new Array();

Ok thats great we now have an array, but the problem is we dont have any data inside of our array, thats not very useful so we will now place data inside of our array, we do this by using an index number, the index number refers to the position in the array.

To place a piece of data inside the first element of our array we would use:

quotes[0] = "Flash is cool!";

As i mentioned before, arrays in flash 5 are zero based, meaning that the first element in the array has an index of zero(0).

So to place a piece of data inside the second element of our array we would use:

quotes[1] = "Flash is my favourite program";

We use this syntax to fill an element of an array with a piece of data:

name_of_array[index] = value;

where name_of_array is the name of your array, the index is the position in your array and the value is the piece of data you want to add to your array.

So the code we created earlier using variables:

quote1 = "Flash is cool!";
quote2 = "Flash is my favourite program";
quote3 = "Flash rules";

can also be written as follows using arrays:

quotes=new Array();
quotes[0] = "Flash is cool!";
quotes[1] = "Flash is my favourite program";
quotes[2] = "Flash rules";

Thats all great, but that is still alot of typing, we can also create an array of values using this syntax:

name_of_array = new Array("value1","value2","value3");

So basically the same as the code we wrote earlier, but in one long line of code, value1 will be the first element of your array, value2 the second element of your array and so on....