文字方块 Actionscript 3.0

Word Square Actionscript 3.0

使用用户输入的单词的字母,我想通过在每个 line.For 示例中将单词的字母向左移动一个位置来打印一个正方形,因为 COMPUTERS 有九个字母,它的正方形将是九个字符向下九个字符。在每一行中,每个字符都将移到末尾。但是,下面的程序只进行一次迭代。请指教。谢谢!

btnDetermine.addEventListener(MouseEvent.CLICK, displayVowels);

function displayVowels(e: MouseEvent): void {
var str1:String;
var str2:String = "";
var i:Number;

str1 = String(txtinString.text);
i=0;

for (i=0; i<str1.length;i++){
str2 = str2 + str1.charAt(i);
}

str2 = str2 + str1.charAt();

lblString.text += str1.charAt(i) + "\r" + str2 ;


}
function displayVowels(e:MouseEvent):void {
    //defines your original string
    var myString:String = String(txtinString.text);
    //the total character length of the original text, determine how many lines to print
    var tLength:int = myString.length; 

    //clears out the textfield in case theres already something on it
    lblString.text = "";

    //print the first line
    lblString.appendText(myString);

    //this loops through every line except line1, we printed line1 above
    //thus tLength - 1
    for (var line:uint = 0; line < tLength - 1; line++) {
        //line break
        lblString.appendText("\n");

        //shift the characters
        myString = shiftChar(myString);

        //print the result into the textfield
        //use appendText instead of textfield += "new text'
        lblString.appendText(myString);
    }


}

function shiftChar(_myString:String):String {
    //save the char at the front, add it to the back later
    var offset:String = _myString.charAt(0);
    //slice the original string so that the first char is now removed
    _myString = _myString.slice(1, _myString.length);
    //add the first char of the original string to the back
    _myString = _myString + offset;

    //return the final results
    return _myString;
}