`

Wednesday, September 15, 2010

Using sortOn in AS3 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!




No comments: