Naro
Naro

Reputation: 27

actionscript 3 array question

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;

Upvotes: 0

Views: 99

Answers (2)

Tyler Egeto
Tyler Egeto

Reputation: 5495

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

Upvotes: 2

longstaff
longstaff

Reputation: 2051

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
} 

Upvotes: 0

Related Questions