2017-05-03 39 views
2

更新的代碼讓我更接近。增量有些問題,但我不能把手指放在上面。如何將此代碼轉換爲函數? (Array to TextFields)

var myMovies:Array = ["Source Code", "Alice in Wonderland", "Zootopia", "Shrek", "Harry Potter"]; 

var inc:Number = 500; // starting vertical position 
var increment:Number = 0; 

function addField() { 
     var textBox:TextField = new TextField(); // assigns a variable to create a new text field 
     addChild(textBox); // adds the text field to the document 
     textBox.x = 150; // formats horizontal positioning 
     textBox.y = inc; // formats vertical positioning 
     inc-= 100; // subtracts 100px from vertical positioning 
     textBox.text = myMovies[increment]; 
    increment++;// inserts array string into text box // goes to and stops on frame 2 
} 


if (increment < 5) { 
    addField(); 
} else { 
    gotoAndPlay(3); 
    } 
+0

你用什麼來佈置你的文本字段?聽起來像是一個定位問題? – Michael

+0

你說得對 - 我修改了上面的代碼以包含位置格式。 :)任何提示都表示讚賞。計數器出現錯誤,導致代碼無法按建議工作。 – Lexii

回答

2

可以逆轉與Array.reverse()方法初始陣列:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#reverse()

myMovies = myMovies.reverse(); 
myText.text = myMovies.join("\n"); 

好吧,讓使你的腳本正確。

var myMovies:Array = ["Source Code", "Alice in Wonderland", "Zootopia", "Shrek", "Harry Potter"]; 

// If you need the items to be sorted in backward order, 
// uncomment the following line: 

// myMovies = myMovies.reverse(); 

for (var i:int = 0; i < myMovies.length; i++) 
{ 
    var aField:TextField = new TextField; 

    aField.multiline = false; 
    aField.wordWrap = false; 
    aField.autoSize = TextFieldAutoSize.LEFT; 
    aField.x = 100; 
    aField.y = 100 + i * 100; 
    aField.text = myMovies[i]; 
} 
+0

這只是顛倒了順序。我需要它出現或者在一個文本框或多個文本框,所以最終的結果看起來是這樣的: 我最喜歡的電影 #1 #2 #3 #4 #5 但從#5向上出現。 – Lexii

+0

我不明白爲什麼它是一個問題,但很好,更新。 – Organis

+0

我還是新的,所以也許我不明白你的意思哈哈:')我會試試看。對不起,如果我遇到無知我不是故意的! – Lexii

相關問題