Hello Lee,

Yes I did, if you mean by using the statement

import mx.containers.*;

I think the problem is that the getChildAt() method returns a DisplayObject, 
but I don't 
know how to cast it as an HBox or any other UIComponent.  The DisplayObject 
doesn't 
even have a getChildAt() method.

If I could figure out how to cast the returned DisplayObject as a particular UI 
component 
that would be great.  Thanks.

be well,
Hoyt

--- In [email protected], Lee <[EMAIL PROTECTED]> wrote:
>
> did you import them? 
> 
> ----- Original Message ----
> From: hoytlee2000 <[EMAIL PROTECTED]>
> To: [email protected]
> Sent: Tuesday, April 22, 2008 6:38:47 AM
> Subject: [flexcoders] Re: how do I loop thru dynamically created UI 
> components?
> 
> Unfortunately it didn't work, I get an error saying I am trying to
> implicitly coerce a type not defined in Display Object.  
> 
> be well,
> hoyt
> 
> --- In [email protected], Lee <callistachan@> wrote:
> >
> > Hi, I replied below =)
> > 
> > -- Lee
> > 
> > ----- Original Message ----
> > From: hoytlee2000 <hoytlee2000@>
> > To: [email protected]
> > Sent: Monday, April 21, 2008 5:21:13 PM
> > Subject: [flexcoders] how do I loop thru dynamically created UI
> components?
> > 
> > Hello,
> > 
> > I've created a button to let users add text input fields to the app
> so they can add additional information.  That works fine, however I am
> at a 
> > lost on how to loop thru the newly added fields to get the input so
> I can send it to a php script to store in a sqlite database.  I
> thought I could 
> > iterate through the container using the numchild attr of the
> enclosing container, but it returns a DisplayObject and that's where I
> get stuck.
> > 
> > I don't know how to access the individual attrs (such as the .text
> property) of the DisplayObject.  I have the label and textinput
> components 
> > wrapped in a hbox for formatting purposes.
> > 
> > Also I noticed that when I try to set the id attr of the textfield
> explicitly the getName method returns something entirely differemt
> (see output 
> > after code below).
> > 
> > Any help, tips, or web link would be appreciated.  I'm stumped.
> > 
> > Thanks,
> > Hoyt
> > 
> > my code:
> > 
> > <?xml version="1.0" encoding="utf-8"?>
> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> layout="absolute">
> > <mx:Script>
> >     <![CDATA[
> >         import mx.controls.Label;
> >         
> >         private var numCount:int = 0;
> >         
> >                 // this adds text input fields, it also adds an hbox
> for formating
> >         private function addField():void {
> >             var newHbox:HBox = new HBox();
> >             var newLabel:Label = new Label();
> >             var newTextInput:TextInput = new TextInput();
> >             
> >             numCount = numCount + 1;
> >             debugField.text = numCount + "\n";
> >             
> >             newLabel.text = "Field " + numCount;
> >             newLabel.width = 50;
> >             newTextInput.width = 400;
> >             
> >             newHbox.id = "bbox" + numCount;
> >             debugField.text += newHbox.id + "\n";
> >             
> >             newHbox.addChild(newLabel);
> >             newHbox.addChild(newTextInput);
> >             
> >             vbox.addChild(newHbox);            
> >         }
> >         
> >                // I use this function to test output and this is
> where I need help.  I want to
> >                // iterate through all the text input fields and read
> the user input
> >         private function getInfo():void {
> >             var i:int = 0;
> >             for (i = 0; i < vbox.numChildren ; i++) {
> >                 var tmpName:String = "hbox" + i;
> >                 var tmpObj:DisplayObject = vbox.getChildAt(i);
> > --------
> > try something like this instead of the previous line (although this
> is kinda longer than typecasting directly)
> > 
> > var tmpObj:HBox = vbox.getChildAt(i);
> > var tmpTxt:TextInput = tmpObj.getChildAt(1);//because the text input
> is the 2nd child you added
> > var str:String = tmpTxt.text;
> > --------
> >                 debugField.text += "Index is: " + i + "\n";
> >                 debugField.text += tmpObj.toString() + "\n";       
>         
> >             }
> >         }
> >         
> >     ]]>
> > </mx:Script>
> >     <mx:Panel id="myPanel" x="460" y="10" width="513" height="297"
> layout="absolute">
> >         <mx:VBox id="vbox" x="10" y="10" height="237" width="473">
> >             <mx:HBox id="hbox0" width="528" backgroundColor="#0A7C55">
> >                 <mx:Label text="Url" width="49" color="#FFFFFF"
> textAlign="center" height="20"/>
> >                 <mx:TextInput width="412"/>
> >             </mx:HBox>
> >         </mx:VBox>
> >     </mx:Panel>
> >     
> >     <mx:TextArea x="44" y="162" height="145" id="debugField"
> wordWrap="true" width="408"/>
> >     
> >     <mx:Button x="44" y="315" label="GetInfo" click="getInfo();"/>
> >     
> > </mx:Application>
> > 
> > 
> > This is the printout I get from the code:
> > 
> > Index is: 0
> > sandbox0.myPanel.vbox.hbox0
> > Index is: 1
> > sandbox0.myPanel.vbox.HBox89
> > Index is: 2
> > sandbox0.myPanel.vbox.HBox96
> > Index is: 3
> > sandbox0.myPanel.vbox.HBox104
> > 
> > why is the id of the added HBox's Hbox89, HBox96, and HBox104?
> instead of Hbox1, Hbox2, Hbox3?
> > 
> > 
> > ------------------------------------
> > 
> > --
> > Flexcoders Mailing List
> > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > Search Archives:
> http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups
> Links
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> >      
> ____________________________________________________________________________________
> > Be a better friend, newshound, and 
> > know-it-all with Yahoo! Mobile.  Try it now. 
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
> >
> 
> 
> 
> ------------------------------------
> 
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives: 
> http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! 
Groups Links
> 
> 
> 
> 
> 
> 
> 
> 
> 
>       
____________________________________________________________________________________
> Be a better friend, newshound, and 
> know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>



Reply via email to