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);
}
}
}
{
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);
}
}
}