?
Solved

indexOf for Array in AS2

Posted on 2009-05-19
2
Medium Priority
?
1,750 Views
Last Modified: 2013-11-11
is there an alternative to indexOf to use for arrays in as2?
0
Comment
Question by:jasotasticon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
blue-genie earned 1000 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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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,…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses

777 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