-1
我想創建一個程序,將傳播節點與數組,我輸入數組節點,首先程序運行良好,但是當我想要將數據排序爲一個貪婪[]數組;用greed.sort();數據不是有序的,請幫助我們。還有一個,如果這些信息是動畫片段或圖片,我怎麼能看到輸出面板上的標籤?像這樣:排序數組中的數據和跟蹤[對象數據]動作腳本3
<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();