伙计们,我想使用 sortOn 对数组进行排序,我很困惑,因为我需要一些自定义排序数组方法来达到我的目的,这是我的数组:
var C:Node = new Node(); var D:Node = new Node(); var E:Node = new Node();
var F:Node = new Node(); var K:Node = new Node(); var L:Node = new Node();
//Node is graphic
var myArray:Array = [C, D, E, F, K, L];
C.name = "C"; D.name = "D"; E.name = "E"; F.name = "F"; K.name = "K"; L.name = "L";
C.z = 2; D.z = 1; E.z = 2; F.z = 1; K.z = 1; L.z = 2;
for (var a:int = 0; a<myArray.length; a++) trace(myArray[a].name+".z : "+myArray[a].z);
//Output is :
//C.z : 2
//D.z : 1
//E.z : 2
//F.z : 1
//K.z : 1
//L.z : 2
我想按名称和 z 值对 myArray[] 进行排序,所以如果我 trace(); myArray 结果是:
for (var b:int = 0; b<myArray.length; b++) trace(myArray[b].name+".z : "+myArray[b].z);
//output is :
//C.z : 2
//E.z : 2
//L.z : 2
//D.z : 1
//F.z : 1
//K.z : 1
那么,如何使用 sortOn() 对 myArray[] 进行排序;方法,以匹配我想要的?