desmond
desmond

Reputation: 35

Getting values from dynamic controls in flex3

I'm new in Flex 3 and ActionScript. I would like to know how do I get the value of the dynamic textboxes via their id.

for (var countz:int = 0; countz < questionCount; countz++)          
{
  hboxtextboxz = new HBox();
  txt = new TextInput();
  txt.id = countz + "";
  hboxtextboxz.addChild(txt);
}

Does anyone have any idea how I get the values out of the dynamic textboxes I created with the for loop?

Upvotes: 2

Views: 468

Answers (2)

midhunhk
midhunhk

Reputation: 5554

To dynamically get all the children of a Container, use the getChildren() method. It will return an Array of UIComponents, If they are TextInput instances, cast them and get the value using the text property.

Sample code to get all the textBoxes from a container which are inside HBoxes.

var children:ArrayCollection = textBoxContainer.getChildren();
for(var i:int = 0; i < children.length; i++)
{
    var hbox:HBox = HBox(children[i]);
    var textBox:TextInput = TextInput( hbox.getChildAt(0));
    if(textBox != null)
    {
        trace(textBox.text);
    }
}

The above code is provided your UI structure is as :

<VBox id="textBoxContainer">
    <HBox>
         <TextInput/>
    </HBox>
     ....
</VBox>

Upvotes: 1

Snukus
Snukus

Reputation: 1302

By values do you mean the text inside of the box?

If you want to access it inside of your for loop just use the variable name:

txt.text

Otherwise if you create your text box in MXML you can set its id parameter and access it using that: (text fields id).text

should give you the text that has been inserted into that box.

Upvotes: 0

Related Questions