views:

1572

answers:

3

Does anyone have any examples on how to create a dynamic number of TextInput boxes and have each of the text being typed in these boxes be bound to a label? For example, say I have an XML file that specifies that I want 3 TextInput boxes. Flex should then take this data, create the TextInput boxes, create bindable variables for each TextInput and create a label to display what is being typed for each TextInput. The biggest issue I'm having with solving this scenario is how to bind a variable amount of data. Any ideas?

A: 

You can't create a new variable for each text input. Just use an array.

eduffy
A: 

Use mx.binding.utils.BindingUtils to create runtime binding.

Here's an article: http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_7.html

Chetan Sastry
+2  A: 

This function creates a pair of textinput/label, where label.text is binded to data in textinput. This should be a good starting point for your code.

private function createTextFieldWithLabel ():void
{
    var tf:TextInput = new TextInput();
    var label:Label = new Label();
    var binding:ChangeWatcher = BindingUtils.bindProperty(label, "text", tf, "text");
    var hbox:HBox = new HBox();
    hbox.addChild(tf);
    hbox.addChild(label);
    addChild(hbox);
}
Hrundik