views:

635

answers:

2

Hi,

I have a tile layout containing a list of TextInputs and text fields , i have created these fields in a custom component using the following code;

var newTextInputs:Array = [];
  var newTextLabels = [];
  var space:Number = 30;
  var count:Number = 0;
  for (var i:String in columnsData)
  {
   //create text labels
   var label:Text = new Text();
   label.name = "label" + count;
   label.text = i;
   newTextLabels[count] = label;
   addChild(newTextLabels[count]);

   // create text fields
   var field:TextInput = new TextInput();
   field.name = "field" + count;
   field.width = 100;
   field.height = 25;
   field.text = columnsData[i];
   newTextInputs[count] = field;
   addChild(newTextInputs[count]);
   count++; 
  }

users are allowed edit the values in each TextInput field, now i need to retrieve the newly udpated values however how can i access these fields? Because the identifiers are created dynamically i cant simply go componentName.InputFieldName, any ideas?

+1  A: 

You can add an event handler for the TileList CHANGE event; when it fires, I think the event.target property will have the specific TextInput field. Alternatively you can look at the TileList.SelectedItem property.

You may also be able to have a DataProvider bound to the TileList instead of your code as shown, which will handle this automatically for you. Try just assigning your NewTextLabels array as the dataProvider.

le dorfier
+2  A: 

I think what you're looking for is getChildByName

later edit: tested with Flash and TextField and it works:

trace(TextField(getChildByName('textfield')).text);
evilpenguin
so do i need to specify the name of the textInput (eg field1) as the parameter and return a DisplayObject, how do i then use the display object to get the text values?cheers
combi001
try a typecast: TextInput(getChildByName('field'+i))
evilpenguin
tested with Flash and TextField and it works: trace(TextField(getChildByName('textfield')).text);
evilpenguin