The sortOn( ) can sort on more than one field
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var cars:Array = new Array( );
cars.push({make: "H", year: 1997, color: "maroon"});
cars.push({make: "Chrysler", year: 2000, color: "beige"});
cars.push({make: "Mercedes", year: 1985, color: "blue"});
cars.push({make: "Fiat", year: 1983, color: "gray"});
cars.sortOn(["year", "make"]);
for (var i:int = 0; i < cars.length; i++) {
trace(cars[i].color + "\t" +
cars[i].year + "\t" +
cars[i].make);
}
cars.sortOn(["make", "year"]);
for (var i:int = 0; i < cars.length; i++) {
trace(cars[i].color + "\t" +
cars[i].year + "\t" +
cars[i].make);
}
}
}
}
Related examples in the same category