We just launched Widgetic! Add beautiful HTML5 widgets to your website. See Widgets >
LOGIN Don't have an account yet?   Register

Forgot password?

Using sortOn in AS3

We’re working on a project where we had to sort the vector in different ways, depending on the user selection.

So we find the sortOn function in AS3, which is perfect. But there’s a problem!

If you want to sort an array of objects, by one of it’s fild which is numeric, the sortOn sorts them as if the numbers are strings.

The solution is to add an additional parameter, like this:

 programArray.sortOn("popularity-score", Array.NUMERIC);

Note you can pass more parameters, for example sort them descending:

 programArray.sortOn("popularity-score", Array.DESCENDING | Array.NUMERIC);

Hope this saves you some time when you need to use it! :)

This post has 3 comments | Post your comment


October 25, 2009 at 6:57 pm

Thanks for posting this – looked everywhere through Adobe forums (useless and convoluted) and couldn’t find a solution. This was perfect.



October 26, 2009 at 7:08 am

Glad it was useful! We too spent some time on Adobe website and without much success either! :)



February 1, 2014 at 4:48 am

i was trying to sort the z index of display objects, basically sort the order of display based on the scale of the object

so just to add to this, one needs to specify the parameter as a string, example:



Leave a Reply

blog entries RSS Feedproducts RSS Feed


Warning: Invalid argument supplied for foreach() in /nfs/c03/h01/mnt/55300/domains/flabell.com/html/app/webroot/blog/wp-content/plugins/flabell/flabell.php on line 272

Popular Files

Download the plugin above
Read more about Flabell WordPress plugin


Search the blog