Solved

indexOf for Array in AS2

Posted on 2009-05-19
2
1,708 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 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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 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…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

726 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