Flex 3: Dynamic creation and binding of textinput

actionscript-3apache-flex

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?

Best Answer

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