PDA

View Full Version : Filling textboxes from an array


headless_pnub
09-21-2007, 01:29 PM
Hello,

I've got an array with names in it and i'm looking for a way to display those names in individual textboxes. I've used a for loop which works great when I trace it, but i'm not sure how to get each name put into a seperate box.

I guess i need to use another loop to have "textbox" + i, but how would this work in AS3? :confused:

Sorry, I'm new to AS3 and still getting to grips with it.

The end product I'd actually like is for the textbox to be dynamically created and given a instance name, but right now I just want to be able to return something in my boxes.

Any help would be greatly recieved.
Thanks.

jsimpson
09-21-2007, 04:33 PM
var i:int = 0;
var arrayLength:int = myArray.length;
var textFmt:TextFormat = new TextFormat(param, param, param)
for(i = 0; i < arrayLength; i++){

var myText:TextField = new TextField();
myText.defaultTextFormat = textFmt;
myText.text = myArray[i];
myText.x = 20;
myText.y = 20 + i * 20;
addChild(myText);
}


If you want to edit the names and text fields latter also push them into a new array, and they will corrispond to the data in the original.

nikefido
09-21-2007, 09:38 PM
That doesn't give the text fields there own instance name, however, correct?
Or are you saying to put the text fields into another array for later editing? (You can pass objects into arrays, right?)