Flex 3: Dynamic creation and binding of textinput

一世执手 提交于 2019-12-11 17:46:54

问题


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?


回答1:


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



回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/966047/flex-3-dynamic-creation-and-binding-of-textinput

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!