Solved

indexOf for Array in AS2

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
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 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.

763 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

10 Experts available now in Live!

Get 1:1 Help Now