0
votes

I want to add a button which when clicked adds another text field. I am using adobe flash builder to write the application therefore it needs to be in MXML or actionscript. Any ideas as to how this could be done?

The eventhandler button currently points to this code, however after the first addition of the textbox, it stops and doesn't add any more. How do I make a loop to keep adding textfields for every time the button is clicked?

<fx:Script>

    <![CDATA[
        protected function tableID(event:MouseEvent):void
        {               
            var name:TextInput = new TextInput;
            addElement(name);
            name.move(50, 200);
        }
    ]]>
</fx:Script>

MXML:

<s:Button id="addBtn" x="175" y="450" label="+" click="tableID(event)" />
2
How do you know that the textinput is only being added on the first click, and not in any subsequent clicks? Looking at your code, my assumption would be that every time you click the button, the textbox IS being added, however, it is being added on top of the previous textinput, so you cant visually see it. Can you also post your MXML for the button node, with the event hook up. - Kaushal De Silva

2 Answers

0
votes

Just use a boolean variable for the text field. Set the variable for includeInLayout & visible for text field. On clicking the button set the condition for the boolean variable to be true or false. I think this will help you out.

0
votes

You can try this way:

<fx:Script>
    <![CDATA[
        import mx.controls.TextInput;
        protected function bt_clickHandler(event:MouseEvent):void
        {
            // TODO Auto-generated method stub
            var item:TextInput = new TextInput();
            item.width = 50;
            _parent.addElement(item);
        }
    ]]>
</fx:Script>

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:Tile id="_parent" width="100%" height="100%">
    <s:Button id="bt" label="+" click="bt_clickHandler(event)"/>
</mx:Tile>