Q:

How to dynamically add textinput in AS3 AIR app

Is there a way to dynamically add textinput fields in a AS3/Air app built for mobile devices?
I have a form where the user needs to enter some information (name, address, DOB etc) and there is a section for the user to enter contact numbers. I would like the ability to add unlimited amounts of contact numbers. To do this, I have an 'add number' button. The user clicks this and the screen adds 1 new textinput to the bottom of the list.
Any guidance or code sample is appreciated.

A:

I was bored so I made a little demo. Check out the link below.
Demo: http://ronnieswietek.com/_random/phone_nums.swf
Source: http://ronnieswietek.com/_random/phone_nums.fla
The code below may be a bit bloated but that is for demo purposes
import flash.events.MouseEvent;
import fl.controls.TextInput;
import flash.display.Sprite;

var lastY:Number = origPhoneField.y;
var fieldHolder:Sprite = new Sprite();
fieldHolder.x = origPhoneField.x;
fieldHolder.y = origPhoneField.y + 35;
addChild(fieldHolder);

function addPhoneField(e:MouseEvent):void
{
    //-- clicking the plus icon will add a new custom text input
    //-- its only custom because I added a minus button to it
    var newInput:CustomTextInput = new CustomTextInput();
    newInput.y = (fieldHolder.numChildren > 0) ? fieldHolder.height + 5 : 0;
    fieldHolder.addChild(newInput);
    newInput.minusBtn.addEventListener(MouseEvent.CLICK, removePhoneField);
}
addBtn.addEventListener(MouseEvent.CLICK, addPhoneField);

function removePhoneField(e:MouseEvent):void
{
    //-- clicking the minus will remove the movie clip and reposition the other fields vertically
    fieldHolder.removeChild(e.target.parent);
    for (var i:int = 0; i < fieldHolder.numChildren; i++)
    {
        var target = fieldHolder.getChildAt(i);
        target.y = (i * 35);
    }
}

function showNumbers(e:MouseEvent):void
{
    //-- for demo purposes, this will output all the values
    outputWin.text += origPhoneField.text + "\n";
    for (var i:int = 0; i < fieldHolder.numChildren; i++)
    {
        var target = fieldHolder.getChildAt(i);
        outputWin.text += target.theField.text + "\n";
    }
    outputWin.text += "================\n";
}
showNums.addEventListener(MouseEvent.CLICK, showNumbers);

