如何在Actionscript 3中获取动态TextInput字段值

时间:2011-09-30 06:04:33

标签: actionscript-3 flex actionscript

您好在函数中创建dynamic TextInput个字段。 需要在另一个函数中获取这些字段的值。任何人都可以对此有所了解。

for(var i:int=0;i<answers.length;i++)
                {       
                    txtbox = new spark.components.TextInput();                  
                    var lblBox:spark.components.Label = new spark.components.Label();                   
                    lblBox.id = "lbl"+i.toString();
                    lblBox.text = String(answersLabel.getItemAt(i) );
                    lblBox.width = 10
                    lblBox.x = xPos-15;
                    lblBox.y = yPos;
                    QuestionAnswer.addElement(lblBox);                  
                    txtbox.id   = "text"+i.toString();
                    txtbox.x = xPos;
                    txtbox.y = yPos;
                    QuestionAnswer.addElement(txtbox);                  
                    xPos += 200;
                }

2 个答案:

答案 0 :(得分:2)

var txt:TextField;
var i:uint;
var ary:Array = new Array();
function txtCreation ():void {
    for( i=0;i<5;i++)
    {
        txt = new TextField();
        txt.text = "txt"+i;
        addChild(txt);
        txt.x = 50 + txt.width *i;
        txt.y = 20;
        ary.push(txt);  
    }
}
txtCreation();

for(i=0;i<ary.length;i++)
{
    trace("array values : " +ary[i].text);
}

答案 1 :(得分:0)

只需查看文本字段的文本变量即可。

var textFromField : String = myInputText.text;