AS3 TextField - unwanted carriage return when setting value to ""

Posted by jevinkones on Stack Overflow See other posts from Stack Overflow or by jevinkones
Published on 2010-01-08T18:55:59Z Indexed on 2010/05/30 21:02 UTC
Read the original article Hit count: 318

I have an input TextField and have a KeyboardEvent.KEY_DOWN even listener on the stage to listen for the Keyboard.ENTER event. The event listener adds the entered text to an array or whatever, and then clears the TextField. The problem is that when the Enter key event fires and the TextField value is set to "", it leaves a carriage return in the TextField and the cursor positioned on the second line. WTF? I've been coding AS2 and AS3 for a LONG time and have never ran into this before. Am I losing my mind? Please help, people! :-)

Example:

var myTextArray:Array = new Array();
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);

function onKeyDown(e:KeyboardEvent):void{
    if(e.keyCode == Keyboard.ENTER){
        if(_inputText.text != null){
            myTextArray.push(_inputText.text);
    }
    _inputText.text = "";
    }
}

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about input