PDA

View Full Version : getChildAt(i).text?



danthemilk
February 28th, 2008, 05:00 PM
I'm sure this is a simple thing to do, but I'm can't seem to find an example anywhere.

I've got some dynamically generated textField objects that have been added to a container, and I want to get the text from them and store it as a variable.

how do I target that textbox's text?

I can target the textbox...

container.getChildAt(i);

but how do I get the text from the textbox

container.getChildAt(i).text; ??

sorry for the silly question, I know I should be able to figure this one out but I'm new to AS3.

Thanks

danthemilk
February 28th, 2008, 07:52 PM
Nobody? This seems like such a simple question? I don't know why I can't get it.

Dazzer
February 29th, 2008, 01:06 AM
Make sure your displayObject is cast as a TextField before accessing the 'text' variable. Not doing so will result in a compilation error, as 'text' variable is not a property of displayObject.

therobot
February 29th, 2008, 02:54 AM
Try assigning the getChildAt to a variable...


var myText = container.getChildAt(i);
myText.text = "whatever".

richwilliamsuk
February 29th, 2008, 05:41 AM
i made a variable at the start:- var tester:Object = new Object(); then accessed the text property from that object and it seemed to work fine:-

tester = container.getChildAt(i)
tester.text = "test" + i;
trace(tester.text);