Solved

indexOf for Array in AS2

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SCCM 2012 - Deploy Flash 16 7,091
IE 11 Flash Player issue 7 252
Microsoft WSUS 4 110
Flash being Disabled - help! 20 343
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
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 live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to how to record live broadcast.

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