Vector.<Point>.sortOn()? How to make a compare function?
okay in as2 had array of points. , sorted this: myarray.sorton(["x", "y"],[array.numeric, array.numeric]);
i changing code on as3 , thought change array vector of points. realized there isn't sorton method vectors.
the sort method takes compare function , think have working. wondering if there better or cleaner way of writing compare functions? new me.
function compare(p1:point,p2:point):number {
if (p1.x>p2.x || (p1.x==p2.x && p1.y>p2.y)) {
return 1;
} else if (p1.x<p2.x || (p1.x==p2.x && p1.y<p2.y)) {
return -1;
}
return 0;
}
i feel sure using faster vector arrays , doing own sort won't fast using array , doing sorton. also, limit flash player 10, although common now, isn't everywhere player 9 is.
your original as2 code works unchanged in as3:
var myarray:array = [new point(10,10),new point(10,5),new point(5,33)]
myarray.sorton(["x", "y"],[array.numeric, array.numeric]);
trace(myarray)
(x=5, y=33),(x=10, y=5),(x=10, y=10)
More discussions in ActionScript 3
adobe
Comments
Post a Comment