If you want to loop over the keys (the names of the components), you
need a for-in loop:

 

    for (var key:String in dynamicallyCreatedComponents)

 

A for-each-in loop loops over the values (the references to the
componetns).

 

There is no such thing as a for-each-as loop as you've written below.

 

Gordon Smith

Adobe Flex SDK Team

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Jason B
Sent: Wednesday, August 20, 2008 11:09 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: getChildByName using it to get the value of a
textbox

 

Can i loop through the items in that object 

example

for each(var items:String as dynamicallyCreatedComponents){
var t:TextInput = dynamicallyCreatedComponents[items] as TextInput;
Alert.show(t.text); //THROWS ERROR

}

I was hoping to set the array key dynamically and loop through it later?
can this be done Gordan

--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
, "Gordon Smith" <[EMAIL PROTECTED]> wrote:
>
> Declare an instance variable of type Object or Dictionary for storing
> named references to dynamically created components:
> 
> 
> 
> public var dynamicallyCreatedComponents:Object = {};
> 
> 
> 
> In a method where you create a component at runtime, do
> 
> 
> 
> var b:Button = new Button();
> 
> b.label = "OK";
> 
> dynamicallyCreatedComponents["okButton"] = b;
> 
> 
> 
> Later you can access this button as follows:
> 
> 
> 
> dynamicallyCreatedComponents["okButton"]
> 
> 
> 
> Gordon Smith
> 
> Adobe Flex SDK Team
> 
> 
> 
> ________________________________
> 
> From: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
[mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of Jason B
> Sent: Tuesday, August 19, 2008 7:38 AM
> To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> 
> Subject: [flexcoders] Re: getChildByName using it to get the value of
a
> textbox
> 
> 
> 
> thanks Tracy could you provide an example of how this is done,
> examples always help others out, or tell me what i should be searching
> for to find an example
> 
> --- In flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com>
> , "Tracy Spratt" <tspratt@> wrote:
> >
> > A good solution to that issue is to maintian a structure of
references
> > pointing to each dynamically created component.
> > 
> > 
> > 
> > I personally like an Associative Array/Object/Hashtable. This is way
> > more positive than attempting to loop through the DOM.
> > 
> > 
> > 
> > There will be plenty examples available.
> > 
> > 
> > 
> > Tracy
> > 
> > 
> > 
> > ________________________________
> > 
> > From: flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com>
> [mailto:flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com>
> ] On
> > Behalf Of Jason B
> > Sent: Monday, August 18, 2008 5:47 PM
> > To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com> 
> > Subject: [flexcoders] Re: getChildByName using it to get the value
of
> a
> > textbox
> > 
> > 
> > 
> > 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 flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com>
> <mailto:flexcoders%40yahoogroups.com>
> > , "Gordon Smith" <gosmith@> 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: flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com>
> <mailto:flexcoders%40yahoogroups.com>
> > [mailto:flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com>
> <mailto:flexcoders%40yahoogroups.com>
> > ] On
> > > Behalf Of Jason B
> > > Sent: Monday, August 18, 2008 8:07 AM
> > > To: flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com>
> <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);
> > >
> >
>

 

Reply via email to