Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 TextField as3获取输入_Actionscript 3_Actionscript - Fatal编程技术网

Actionscript 3 TextField as3获取输入

Actionscript 3 TextField as3获取输入,actionscript-3,actionscript,Actionscript 3,Actionscript,我有一个无法解决的问题,我想问我做错了什么。我的想法应该是,当我创建文本字段时,我想从中读取,但它没有 function click2(e:MouseEvent):void{ e.currentTarget.removeEventListener(MouseEvent.CLICK, click2); fx=e.target.x+400; fy=e.target.y+300; var i:int; i=2; trace(str); trace

我有一个无法解决的问题,我想问我做错了什么。我的想法应该是,当我创建文本字段时,我想从中读取,但它没有

function click2(e:MouseEvent):void{
    e.currentTarget.removeEventListener(MouseEvent.CLICK, click2);
    fx=e.target.x+400;
    fy=e.target.y+300;
    var i:int;
    i=2;
    trace(str);
    trace(e.target.name);
    var  line:Shape = new Shape();
    line.graphics.lineStyle(1,0xFF0000,2);
    line.graphics.moveTo(sx,sy);
    line.graphics.lineTo(fx,fy);
    this.addChild(line);
    var inputField:TextField = new TextField();
    inputField.border = true;
    inputField.type = TextFieldType.INPUT;
    inputField.width = 23;
    inputField.height = 18;
    inputField.x = (sx+fx)/2;
    inputField.y = (sy+fy)/2;
    inputField.multiline = false;
    inputField.maxChars = 3;
    inputField.restrict = "0-9"; 
    str=inputField.text;
    addChild(inputField);
}

在这段代码中,我创建了一行,在它附近出现了一个文本字段,您需要在其中输入该行的值,但我无法获取它,当我要跟踪STR值时,它为null,文本应该由用户编写,我应该阅读它…

如果要检查用户添加到文本输入中的数据,您必须侦听更改事件。之后,您可以访问提供的文本

function click2(e:MouseEvent):void{
    ...
    inputfield.addEventListener(Event.CHANGE, checkInput);
}

function checkInput(e:Event):void {
    //receive input value and validate it
    var textfield:TextField = e.target as TextField;
    var str:String = textfield.text;
    ...
}

您不会将任何文本指定给文本字段。那为什么里面会有东西呢?