getIndex AS3 version

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

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!

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

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;
}

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


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

}