>From the docs on Array.sort():

"All elements, whatever the data type, are sorted as if they were strings, so 100 precedes 99, because "1" is a lower string value than "9". "

But you can easily change the default sort behavior by doing this:

arr.sort(Array.NUMERIC);

-Tom

On 6/8/06, Jim Robson <[EMAIL PROTECTED]> wrote:

Thanks Tom,

 

I believe array indices are ints, not strings. However, I also believe that datagrid indices are strings, because when I used the Array.sort() function on the DataGrid.selectedIndices array, the order was all messed up. For example, "10" came before "2". For that reason, I ended up writing a custom sort function to get around the issue.

 

Thanks again!

 

Jim

 


From: flexcoders@yahoogroups.com [mailto: flexcoders@yahoogroups.com] On Behalf Of Tom Bray
Sent: Thursday, June 08, 2006 1:07 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] selectedIndices are Strings???

 

Try either of these two options:

            for( var i:int; i < arr.length; i++ )
            {
                trace( arr[i] );
            }
           
//or

            for each( var i:int in arr )
            {
                trace( i );
            }

The for...in loop that you're using is for iterating over the properties of objects, which it expects to evaluate as strings.  So, in your for...in loop, the var i refers to the indices of the array, not the values you're looking for which are the selectedIndices of your dg.  The for...each loop above is new to AS3 and is the simplest way to do what you want.

HTH,

Tom

On 6/8/06, Jim Robson <[EMAIL PROTECTED]> wrote:

I don't understand why DataGrid.selectedIndices returns an array of Strings. I thought that indices were generally integers. (For example, Array.indexOf returns an int.)

Can anyone explain why the selected index of a DataGrid is a String?

When "dgTest" is a DataGrid instance, the following code generates a compiler error:

 

 

var arr:Array = dgTest.selectedIndices;

for(var i:int in arr){

// do something

}

 

The error that the compiler returns is as follows:

"Implicit coercion of a value of type String to an unrelated type int.  "

 


__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to