2011-06-21 82 views
1

我在應該接受5位美國郵政編碼的表單上有一個文本區域控件。我已經爲控件分配了一個keyUp事件,該事件檢查輸入的字符數,直到達到5,然後強制換行。在textarea中移動光標以結束

public function forceNewLine(event:KeyboardEvent):void 
{ 
    var maxLineChars:int = 5; 
    var currentLine:int = 1; 
    var numChars:int; 

    numChars = (txtList.text.length); 
    currentLine = Math.round(txtList.text.length/6); 

    if (numChars == (maxLineChars * currentLine)) 
    { 
     txtList.text = txtList.text + "\n"; 
     txtList.setCursorPosition() 
     //This is not a function I have defined but I think I need too.. 
    } 
} 

<s:TextArea id="txtList" keyUp="forceNewLine(event)"/> 

它工作正常,除了當插入新行時,光標移動到textarea的開頭。我想讓它走到最後。

回答

5

嘗試使用spark textArea的selectRange函數。

txtList.selectRange(txtList.text.length, txtList.text.length)