Arulmurugan
Arulmurugan

Reputation: 107

How to get dynamic TextInput field values in Actionscript 3

Hi creating dynamic TextInput fields in a function. Need to get the values of those fields in another function. Can anyone throw some light on this.

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

Upvotes: 0

Views: 2294

Answers (2)

Benny
Benny

Reputation: 2228

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

Upvotes: 2

Mattias
Mattias

Reputation: 3907

Just look at the text variable for the textfield.

var textFromField : String = myInputText.text;

Upvotes: 0

Related Questions