I think I'm being very dumb here, but the indexof() function doesn't
seem to work as advertised.  I'm working with Flex3.

Here's a simplified version of the code:

var s:int = new int;
var i:int = new int;
var l:int = new int;
var aYears:Array = new Array("2002", "2003", "2004", "2005");
var o:Object = new Object;
var myYear:int = new int;

myYear = 2004;

o = myYear;
s = aYears.indexOf(o, 0);

Alert.show("Test this    " +  s.toString()); // here s is -1, showing
that it didn't find the string in the array
s = aYears.indexOf("2004",0);
Alert.show("Test this    " +  s.toString()); // here s is -1, showing
that it didn't find the string in the array
s = aYears.indexOf(myYear,0);
Alert.show("Test this    " +  s.toString()); // here s is -1, showing
that it didn't find the string in the array

s = -1;
i = 0;
l = aYears.length;
while (i<l)
{
        if (aYears[i] == myYear)
        {
                s = i;
        }
        
        i++;
}

Alert.show("Test this    " +  s.toString()); // here s is 3, showing
that it did find the string in the array

The help says that indexOf "[s]earches for an item in an array by using
strict equality (===) and returns the index position of the item."  

Can someone tell me how I am being stupid?  :)

Thanks,

Bob

Reply via email to