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

I have an input TextField and there is a KeyboardEvent.KEY_DOWN listener on the listener to listen to the Keyboard.ENTER event. An event listener adds the entered text to an array or something else, and then clears the TextField. The problem is that when the Enter key event is triggered and the value "Text" is set to "", it leaves the carriage return to the TextField and the cursor located on the second line. WTF? I have encoded AS2 and AS3 for a long time and have never encountered 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 = "";
    }
}
+3
8

KEY_DOWN KEY_UP. ( )

+1

KEY_DOWN → → KEY_UP →

( ):

Message.addEventListener(KeyboardEvent.KEY_DOWN, function(e:KeyboardEvent):void
                     {
                        if(e.keyCode == Keyboard.ENTER)
                        {
                            // Your code...
                        }
                     });
Message.addEventListener(KeyboardEvent.KEY_UP, function(e:KeyboardEvent):void
                         {
                             if(e.keyCode == Keyboard.ENTER)
                             {
                                 Message.text = "";
                             }
                         });
+1

, , TextField , ?

KeyboardEvent.KEY_UP?

0

? , onKeyDown , . onKeyDown, flash .

, .

0

Flash ( IDE), Control → Disable Keyboard Shortcuts . KEY_UP.

0
inputfield.addEventListener(Event.CHANGE, onChange);

private function onChange(e:Event):void {
if ( inputfield.text.charCodeAt(inputfield.text.length - 1) == 13 ) {
inputfield.text = inputfield.text.substr(0, inputfield.text.length - 1);
}
}
0

, , . fla. .

0

, - - . textField.text = "" ( -), , , .

-1

Source: https://habr.com/ru/post/1727801/


All Articles