This seems very inefficient. I don't see any reason to loop over
anything to find a component that you dynamically created.

 

If you know you're going to create a single TextInput, declare an
instance var like

 

    private var textInput:TextInput;

 

If you know you're going to create a bunch of components that you want
to access by index, declare an Array.

 

If you know you're going to create all kinds of components that you want
to access by some kind of non-index identifier, declare an Object or a
Dictionary that maps the identifier to the reference.

 

Gordon Smith

Adobe Flex SDK Team

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Luke Vanderfluit
Sent: Monday, August 18, 2008 3:25 PM
To: [email protected]
Subject: Re: [flexcoders] Re: getChildByName using it to get the value
of a textbox

 

Hi.

I wrote a getChildById function for this purpose/use case...
I create the grid and its children dynamically at runtime and give the
DisplayObjects 
numerical ids.
Its one thing you miss in flex if you're used to using getElementById in
javascript.

So... this is container specific... I havent gotten round to generifying
it yet...

private function getChildById(g:Grid, id:int):DisplayObject {
for each (var gr:GridRow in g.getChildren()) {
for each (var gi:GridItem in gr.getChildren()) {
if (!(gi.getChildAt(0) is HBox)) {
if (gi.getChildAt(0) is Text) {
if (Text(gi.getChildAt(0)).id == String(id)) {
return Text(gi.getChildAt(0));
}
}
if (gi.getChildAt(0) is TextInput) {
if (TextInput(gi.getChildAt(0)).id == String(id)) {
return TextInput(gi.getChildAt(0));
}
}
}
}
}
return null;
}

hth.
Kr.
Luke.

Jason B wrote:
> Because the items are not in MXML its in actionscript which
> dynamically creates the items for my form from a database and i want
> to dynamically loop the text box's so i can then save the data back to
> the database.
> you cant refer to a ID since the components are created at runtime
> 
> 
> 
> --- In [email protected]
<mailto:flexcoders%40yahoogroups.com> , "Gordon Smith" <[EMAIL PROTECTED]>
wrote:
>> Why are you trying to use getChildByName to get a reference to a
>> component? If you give it an 'id' attribute in MXML, you can then
refer
>> to it by that id.
>>
>> 
>>
>> Gordon Smith
>>
>> Adobe Flex SDK Team
>>
>> 
>>
>> ________________________________
>>
>> From: [email protected]
<mailto:flexcoders%40yahoogroups.com>
[mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
] On
>> Behalf Of Jason B
>> Sent: Monday, August 18, 2008 8:07 AM
>> To: [email protected] <mailto:flexcoders%40yahoogroups.com> 
>> Subject: [flexcoders] getChildByName using it to get the value of a
>> textbox
>>
>> 
>>
>> when using getchildbyname variable i've not been able to get the
value
>> can someone please post an example of how to get a value using
>> getChildByName.
>>
>> var test:DisplayObject = this.getChildByName("inputtext" + i);
>>
> 
> 
> 
> ------------------------------------
> 
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
<http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt> 
> Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo
<http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo> ! Groups
Links
> 
> 
> 

-- 
Luke Vanderfluit
Analyst / Web Programmer
e3Learning.com.au
08 8221 6422

 

Reply via email to