Solved

indexOf for Array in AS2

Posted on 2009-05-19
2
1,597 Views
Last Modified: 2013-11-11
is there an alternative to indexOf to use for arrays in as2?
0
Comment
Question by:jasotasticon
2 Comments
 
LVL 39

Accepted Solution

by:
blue-genie earned 250 total points
ID: 24424806
what exactly are you trying to achieve?
use a for loop to loop through your item arrays convert each item to a String and use the indexOf for the String.

0
 
LVL 37

Assisted Solution

by:CyanBlue
CyanBlue earned 250 total points
ID: 24424946
No...  indexOf() is not supported in AS2...  But you can create your own if you really want to...  Of course this code won't cover all the possibility, but you could expand from this...

CyanBlue
Array.prototype.indexOf = function (element)

{

	var _len:Number = this.length;

	for (var i:Number = 0 ; i < _len ; i++)

	{

		if (this[i] == element)

		{

			return i;

		}

	}

	

	return -1;

}
 

var arr1:Array = new Array(12, 34, 56, 78, 90);

trace(arr1.indexOf(34));     // 1
 

var arr2:Array = new Array("Action", "Script", "Hello", "World");

trace(arr2.indexOf("Hello"));     // 2

trace(arr2.indexOf("world"));     // -1

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now