The above code is of little value without an array, and I am sure you are
probably still blinking profusely from the vague introduction paragraph. So,
let's try a small test in Flash. Create a new document in Flash, right click on
an empty frame, select Actions, and copy & paste the following code:
[ copy and paste this code in a frame
and press Ctrl + Enter ]
With the code safely copied, press Ctrl + Enter. You will see the number 4
displayed. What is the number 4? Well, let's take a look at the code. In the
first section of the code, you will find the function required to determine
the index value of an item. This function is the same code that was displayed
earlier; it has not been modified at all, so we will leave that alone.
The following lines are of peculiar interest to us though:
resources = new Array("a",
"b", "c", "d", "e", "f", "g", "h");
location = resources.getIndex("e");
trace(location);
In the first of the third lines, we declare our array called
resources. This array contains nothing more
than the simple letters a,
b, c, d,
e, f,
g, h. In the
next line, we initialize a variable called location
to the value you receive when you call the getIndex
function after passing the value "e".
After the function gets called, Flash takes the letter "e" that was passed,
and tries to find its position in the main array. Once the position is found,
it returns the index value of the letter "e" in the entire array. In this
case, the position of the letter "e" is 4. If, for example, you call the
letter "z", you will receive an answer of -1 to signify that the item was not
found in the array.
I hope this information helped. Feel free to post any questions or comments
on the forums at:
http://www.kirupaforum.com
Cheers!
Thoriphes and Kirupa