# getIndex AS3 version

**URL:** <https://forum.kirupa.com/t/getindex-as3-version/261445>\
**Category:** flash\
**Created:** [May 27, 2008, 6:55pm UTC](https://forum.kirupa.com/t/getindex-as3-version/261445 "2008-05-27T18:55:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tyco](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@tyco](https://forum.kirupa.com/u/tyco)\
**Post date:** [May 27, 2008, 6:55pm UTC](https://forum.kirupa.com/t/getindex-as3-version/261445/1 "2008-05-27T18:55:46Z")

</div>

Hi Kirupa,  
Do you have a AS3 version of your “Getting an Index Position from an Array”  
[http://www.kirupa.com/developer/actionscript/tricks/indexposition.htm](http://www.kirupa.com/developer/actionscript/tricks/indexposition.htm)

I’m still learning AS3. The AS2 version is based on prototype and just wondering how to translate it to the new AS3.

Thank you!

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [May 27, 2008, 7:30pm UTC](https://forum.kirupa.com/t/getindex-as3-version/261445/2 "2008-05-27T19:30:51Z")

</div>

The AS3 Array class already has an _indexOf_ method that does the same thing.

---

<div class="post-metadata">

**Author:** ![tyco](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@tyco](https://forum.kirupa.com/u/tyco)\
**Post date:** [May 27, 2008, 8:42pm UTC](https://forum.kirupa.com/t/getindex-as3-version/261445/3 "2008-05-27T20:42:37Z")

</div>

Krilnon,  
Thank you for your reply. The following AS2 code is what I used the script for. I’m still a bit lost with AS3 just started using this weekend. Any help to get me up to speed is much appreciated!

var aButtons:Array = new Array(btn0, btn1, btn2, btn3); //—Content source is usually fed from an xml doc.

for (var i:Number = 0; i\<aButtons.length; i++) {  
var btnPanel:MovieClip = aButtons\*; //—Usually I have a duplicateMovieClip here  
btnPanel.onRelease = function(){  
var pickedNum:Number = aButtons.getIndex(this);  
trace("pickedNum: " + pickedNum);  
}  
}  
//—Get Index  
Array.prototype.getIndex = function(data) {  
for (var i:Number=0; i\<this.length; i++) {  
if (this\* == data) {  
return i;  
}  
}  
return -1;  
}

---

<div class="post-metadata">

**Author:** ![tyco](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@tyco](https://forum.kirupa.com/u/tyco)\
**Post date:** [May 28, 2008, 3:05am UTC](https://forum.kirupa.com/t/getindex-as3-version/261445/4 "2008-05-28T03:05:29Z")

</div>

Krilnon,  
indexOf()… it is! Thank you so much!

…  
function fMouseUp(evt:MouseEvent) {  
var pickedName:String = evt.target.name;  
pickedNum = aNewBtn.indexOf(pickedName);  
…  
}
