Flash Components      Flash Menu      Flash Gallery      Flash Slideshow      FLV Player      Flash Form      MP3 Player      PhotoFlow      Flash CMS      3D Wall      Flash Scroller

Flash / AS



ASP.net / PHP






  Design & Effects
  Audio & Video
  User Interface





Getting an Index Position from an Array
       code by manny dimatulac (thoriphes); written by kirupa

There are several times when I found it helpful to get the position of an item contained in an array. This quest becomes especially useful when you are dealing with multiple arrays with items in one array corresponding with items in another array.

The code for finding the index position of an item in an array is:

[ the function  required to determine the index value of an item ]

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");

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

Thoriphes and Kirupa



kirupa.com's fast and reliable hosting provided by Media Temple. flash components
The Text Animation Component for Flash CS3
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.
Check out our high quality vector-based design packs! Flash Effect Components
flash menus, buttons and components Digicrafts Components
The best flash components ever! Entheos Flash Website Templates
Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com Purchase & Download Flash Components
flash components Free Website | Make a Website
Streamsolutions Content Delivery Networks Learn how to advertise on kirupa.com