find in the flash.utils package. You can rewrite your "o" Object as a
Dictionary, but ActionScript 3.0 doesn't have the equivalent of the
'sort' keyword in Perl where you can do something like:
// Perl code
foreach $key (sort keys %hash) {}
Unless I'm mistaken, you'd have to write code to sort the Dictionary, so
you may not find this a satisfactory solution.
On the other hand, you can use the Array.sortOn() method to sort the
objects. You just have to create a separate indexed array to do it, the
following builds on your example code:
// create an indexed array that holds the objects in sorted order
var oSorted:Array = new Array();
// add your items to the indexed array
for each (var item in o) {
oSorted.push(item);
}
// sort the indexed array based on the "order" property
oSorted.sortOn("order", Array.NUMERIC);
// Now you can iterate through the sorted array
for (var i=0; i<oSorted.length; i++) {
trace(oSorted[i].order);
}
HTH,
Francis
> -----Original Message-----
> From: [email protected] [mailto:[EMAIL PROTECTED]
On
> Behalf Of rigidcode
> Sent: Monday, May 08, 2006 11:32 AM
> To: [email protected]
> Subject: [flexcoders] How can I sort a hash in Actionscript?
>
>
> If I have an Object (there's no hash class in Actionscript 3 right??),
> is there a way to sort it according to one of it's member's
> properties? For example:
>
> var o:Object = new Object();
>
> o['something'] = new Thing();
> Thing(o['something']).order= 20;
>
> o['another'] = new Thing();
> Thing(o['another']).order= 10;
>
> o['somethingelse'] = new Thing();
> Thing(o['somethingelse']).order= 30;
>
>
> I want to loop through o, in the order of it's member's "order"
> property. I can do this in java and perl and php, but actionscript
> (unbelivably) has no Hash object, right? And "Object" doesn't
> implement ICollectionView. Is there anything else I can do here using
> the API?
>
> thanks
>
>
>
>
>
>
--
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
- Visit your group "flexcoders" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

