bkildow
bkildow

Reputation: 5153

Flex 3: Dynamic creation and binding of textinput

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?

Upvotes: 0

Views: 5679

Answers (3)

Hrundik
Hrundik

Reputation: 1838

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

Upvotes: 7

Chetan S
Chetan S

Reputation: 23823

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

Upvotes: 0

eduffy
eduffy

Reputation: 40262

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

Upvotes: 0

Related Questions