Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AS3 Vector.sort() does not take sorting options?

In AS3, Array.sort() took some nice sorting options like:

  • Array.DESCENDING - sorts the array big to small
  • Array.RETURNINDEXEDARRAY - returns an array of indices so you can track which item got sorted where

But sadly Vector<T>.sort() does not support these features, and simply takes a compareFunction:Function argument so you can write your own sorting logic.

Is there any other way to quickly get a sorted indexed-array of a vector?

like image 233
Robin Rodricks Avatar asked Jun 20 '12 17:06

Robin Rodricks


2 Answers

Check out the documentation : http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Vector.html#sort()

It is still possible to use those options but you have to pass them in as the first parameter instead of the compare function.

 myVector.sort(Array.DESCENDING|Array.RETURNINDEXEDARRAY);
like image 137
Barış Uşaklı Avatar answered Nov 15 '22 18:11

Barış Uşaklı


RETURNINDEXEDARRAY does not work in Flash Player 10+. It just returns the same original Vector<Number>.

Unlike an Array, RETURNINDEXEDARRAY option is ignored for the Vector.sort() method. The returned Vector object is always the reference of the original object.

like image 34
Robin Rodricks Avatar answered Nov 15 '22 18:11

Robin Rodricks