-1

我正在尝试创建一个程序,该程序将使用数组传播节点,我在数组中输入节点,起初程序运行良好,但是当我想对 greed[] 数组中的数据进行排序时;用 greed.sort(); 数据未排序,请帮助我。还有一个,如果此类信息是影片剪辑或图形,我如何在输出面板中看到标签?像这样 :

<pre><code>
 //first program 
    trace("data");  //data --> can display label "data".

    //second program
    var dot:Dot = new Dot(); //graphic from library
    trace(dot);   //[object Dot]    --> Cant show label "dot" ??

所以,我的问题是:1.如何从对象数据中对数组中的数据进行排序?2. 如果数据是图形或影片剪辑,如何在输出面板中显示标签数据?

这是我的完整代码:

var A:Node = new Node();
var B:Node = new Node();
var C:Node = new Node();
var D:Node = new Node();
var E:Node = new Node();
var F:Node = new Node();
var G:Node = new Node();

var node:Array = [];
var goal:Array = [E,G];
var finalCheck:Array = [];

A.x = 55; B.x = 165; C.x = 275; D.x = 55; E.x = 385; F.x = 165; G.x = 385;
A.y = 165; B.y = 55; C.y = 165; D.y = 275; E.y = 55; F.y = 275; G.y = 275;

node.push(A,B,  A,C,  A,D,  
      B,E,  B,C,  C,B,  C,E,  C,G,  C,F,  D,F,  
      C,E,  C,G,  C,F,  B,A,  B,E,  F,G,  F,D,  F,C,  F,G,  
      F,G,  F,D,  D,A,  C,A,  C,B,  C,E,  C,G,  
      D,A,  B,A,  B,E);

for (var d:int = 0; d<node.length; d++){
addChild(node[d]);
}
trace(node.length);

function sortIndex(){
var greedArr = [];
for (var i:int = 0; i<node.length; i++)
{
    if ((i%2 == 0 && node[i] != goal[1] && node[(i+1)] == goal[0]) || 
        (i%2 == 0 && node[i] != goal[0] && node[(i+1)] == goal[1]) ||
        (i%2 != 0 && node[i] != goal[1] && node[(i+1)] == goal[0]) ||
        (i%2 != 0 && node[i] != goal[0] && node[(i+1)] == goal[1])) 
        greedArr.push(node[(i)]);
}
greedArr.sort();
trace("greedArr : "+greedArr+" // "+greedArr.length); //B,B,B,C,C,C,C,C,C,F,F,F
var checker:Array = [];
var Z:int;
for (var k:int = 0; k<greedArr.length/3; k++){
    Z = k*3;
    checker.push(greedArr[Z]);
}
trace("checker : "+checker+" // "+checker.length);   //B,C,C,F
for (var M:int = 0; M<checker.length; M++){
    if (checker[M] != checker[M-1] && checker[M] != checker[M+1]){
        finalCheck.push(checker[M]);
    }
    if (checker[M] == checker[M-1] && checker[M] != checker[M+1]){
        finalCheck.unshift(checker[M]);
    }
    if (checker[M] != checker[M-1] && checker[M] == checker[M+1]){
        finalCheck.unshift(checker[M]);
    }
}
trace("finalCheck : "+finalCheck+" // "+finalCheck.length); //C,C,B,F
for (var e:int = 0; e<finalCheck.length; e++){
    trace((finalCheck[e]).x)
}
}

sortIndex();
4

1 回答 1

0

先生,您的代码很难阅读。似乎属于某种游戏。为什么你让排序过于复杂?如果你真的需要一个 Node 系统来做任何事情,我建议你使用一个流行的框架。它的社区支持并针对比特进行了优化。

于 2013-06-12T06:49:55.830 回答