That #1009 error means that it returned a null from the first line
because it couldn't find the child with that name. getChildByName is
not recursive so you need to be mindful of the nesting of your
requested object.
The following app has the functionality working as you need it, but it
also has a really handy listing function that displays all of the
current children recursively (outputs to the console window in Flex,
if you have the debug player) so that you can see the children that
are present and how they are nested.
Regards,
Nik
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical" horizontalAlign="left">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function showText(evt:MouseEvent):void{
var test:TextInput = this.getChildByName("test"
+ 1) as TextInput;
Alert.show(test.text);
traceDisplayList(this);
}
public function traceDisplayList(container:DisplayObjectContainer,
indentString:String = "->"):void{
var child:DisplayObject;
for (var i:uint=0; i < container.numChildren; i++)
{
child = container.getChildAt(i);
trace(indentString, child, child.name);
if (container.getChildAt(i) is
DisplayObjectContainer)
{
traceDisplayList(DisplayObjectContainer(child), " "
+ indentString)
}
}
}
]]>
</mx:Script>
<mx:TextInput id="test1"/>
<mx:Button label="Button" click="showText(event)"/>
</mx:Application>