Extracting text from a child
In the problem I am working on, container1 (a Sprite) will contain some number
of text fields. I want to be able to access the text stored in each text field
but don't know how to get to it. In the code below, I can get to the name of
the text field, but I know that getChildAt does not have a text property, so
how should I get the values tf1.text and tf2.text from container1?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="init()">
<mx:Script>
<![CDATA[
public function init():void{
var tf1:TextField = new TextField();
var tf2:TextField = new TextField();
tf1.text="xxxxx"
tf2.text="yyyyy"
tf1.name = "text 1";
tf2.name = "text 2";
var container1:Sprite = new Sprite();
container1.addChild(tf1);
container1.addChild(tf2);
for(var i:int=0;i<container1.numChildren;i++){
trace(container1.getChildAt(i).name);
//trace(container1.getChildAt(i).text);
}
}
]]>
</mx:Script>
</mx:Application>
|