Search code examples
apache-flexflex4flex-spark

How to dynamically create layout for s:group in flex


I have a form inside which I have a button Onclick of which I am dynamically adding components to the form. I have successfully added components to the form. I have added a group to club them and give alignment. How can I add horizontal layout to the s:Group.

protected function ADD_CVE_ID_clickHandler(event:MouseEvent):void
            {
var textinput:TextInput = new TextInput;  
var dropdown:DropDownList = new DropDownList;
var textArea:TextArea = new TextArea;
var Grouptest:Group = new Group;
Grouptest.addElement(textinput);
Grouptest.addElement(dropdown);
Grouptest.addElement(textArea);
AddHere.addElement(Grouptest);
}

Solution

  • Use the following code for your requirement:-

            protected function ADD_CVE_ID_clickHandler(event:MouseEvent):void
            {
                var textinput:TextInput = new TextInput();  
                var dropdown:DropDownList = new DropDownList();
                var textArea:TextArea = new TextArea();
                var Grouptest:Group = new Group();
                var horizontalLayout:HorizontalLayout = new HorizontalLayout();
                Grouptest.layout = horizontalLayout;
                Grouptest.addElement(textinput);
                Grouptest.addElement(dropdown);
                Grouptest.addElement(textArea);
                AddHere.addElement(Grouptest);
            }