package
{
    import flash.display.Sprite;
    import flash.events.KeyboardEvent;
    import flash.text.TextField;
    import flash.text.TextFieldType;
    import flash.text.TextFormat;
    
    public class Main extends Sprite
    {    
        var myinput:TextField;
        
        public function Main():void
        {
            init();
        }
        private function init():void
        {
            var inputFormat:TextFormat = new TextFormat();
            inputFormat.size = 14;
            
            myinput = new TextField();
            myinput.type = TextFieldType.INPUT;
            myinput.defaultTextFormat = inputFormat;
            myinput.x = 10;
            myinput.y = 10;
            myinput.height = 20;
            myinput.width = 200;
            myinput.border = true;
            this.addChild(myinput);
            stage.focus = myinput;        
            
            myinput.addEventListener(KeyboardEvent.KEY_DOWN, checkForReturn);
        }
        
        public function checkForReturn(e:KeyboardEvent):void
        {
            if(e.charCode == 13)
            {
                acceptInput();
            }
        }
        
        public function acceptInput():void
        {
            var theInputText:String = myinput.text;
            trace(theInputText);
            myinput.text = "";    //清空输入框中的文字
            //this.removeChild(myinput);
        }
    }
}

相关文章:

  • 2021-08-07
  • 2022-12-23
  • 2021-08-21
  • 2022-12-23
  • 2022-01-20
  • 2021-06-13
  • 2021-04-04
  • 2022-02-22
猜你喜欢
  • 2022-01-19
  • 2023-01-09
  • 2021-11-12
  • 2021-11-03
  • 2022-12-23
  • 2021-04-26
  • 2022-12-23
相关资源
相似解决方案