getChildByName searches the parent for a match with a child's .name property.  
A child's id property is not always the name and is a document reference (the 
outermost tag in the MXML file) so a parent won't always have a child with the 
name of the child's id.

Usually in a script block, because the scope is the document, you just 
reference the id like it is a variable or property.  You don't need 
getChildByName

Alex Harui
Flex SDK Developer
Adobe Systems Inc.<http://www.adobe.com/>
Blog: http://blogs.adobe.com/aharui

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Laurence MacNeill
Sent: Thursday, May 14, 2009 8:09 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Problems with getChildByName();





I have a form that has several dynamically-created children. I'm
having trouble using getChildByName() to retrieve data from them.

Specifically, I create several VBoxes, and in each of those VBoxes I
create children (a label a textInput). Obviously, the TextInput that
I'm trying to get the data from is a child of the VBox, not the
'this', right? So it should be something like
'this.VBox.textInput' right? So I'd getChildByName the VBox first,
then use the result of that to getChildByName the TextInput that's
the child of the VBox, right?

Well, it's not working. when I try to this.getChildByName() the
VBox, I get null instead.

Here's my code, in case I haven't confused you enough. It fails with
a 'cant access property of null object' or something like that.

public function resetFormHandler(): void {
var tempVBox:VBox;
var tempTextInput:TextInput;
var tempComboBox:ComboBox;
var tempCheckBox:CheckBox;
for (var i:int = 0; i<demoList.length; i++) {
tempVBox = this.getChildByName("vbox" +
demoList[i].name) as VBox;
tempTextInput = tempVBox.getChildByName("input" +
demoList[i].name) as TextInput;
tempTextInput.text = "";
}
}

I really don't see why this isn't working -- the VBox was added to
the form with the this.addChild() method. So this.getChildByName
should work to get it back right? I'm completely confused. Unless
getChildByName *doesn't* use the ID field of the VBox to find
it... In which case, I have no clue how I'm gonna find it again.

HELP! :-)

Laurence MacNeill
Mableton, Georgia, USA

Reply via email to