views:

188

answers:

1

I'm trying to create a form that based on the users input would determine how many forms to generate dynamically.

I have a base state with a combo box that contains 1-4. Bases on the users selection I would like to have the next state generate the number of forms. So if you user selects 2 and click next - 2 copies of the form would be display.

I'm just wondering if this is possible how i would go about doing this or if any one knows of any examples?

Thanks!

A: 

This is certainly possible. Here's a rough example to give you some ideas on what you could do. :)

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;

            [Bindable]
            public var dataProviderCombo:ArrayCollection = new ArrayCollection(
                [ {label:"1 Form", data:1}, 
                  {label:"2 Forms", data:2}, 
                  {label:"3 Forms", data:3},
                  {label:"4 Forms", data:4} ]);

            private function GenerateForms():void
            {
                myFormContainer.removeAllChildren();

                for (var i:int = 1; i <= myComboBox.selectedItem.data; i++)
                {
                    var formToAdd:MyCustomForm = new MyCustomForm();
                    myFormContainer.addChild(formToAdd);
                }
            }
        ]]>
    </mx:Script>
    <mx:ComboBox id="myComboBox" x="0" y="10" dataProvider="{dataProviderCombo}" change="GenerateForms();"></mx:ComboBox>
    <mx:HBox id="myFormContainer" y="40">

    </mx:HBox>
</mx:Application>
Jason Towne
Thanks Just was I was looking for!
Adam
Glad I could help out. :)
Jason Towne