views:

34

answers:

2
var arr1:Array = new Array();
arr1.push(item1);
arr1.push(item2);
arr1.push(item3);

then arr1 and its elements get passed to other functions is there a way to know the index of an item in the array?

GetParentArrayIndex(item2) would give me 1;
A: 

presumably you set a function like:

public function GetParentArrayIndex(item:Object):int
{
    for(var i=0; i<arr1.length; i++){
        if(arr1[i] == item){
            return i;
        }
     }
     return -1 //Item not found
} 
shortstick
+1  A: 

Array's have built in functionality for this, myArray.indexOf(obj)

Tyler Egeto