Hello Rick, This is an interesting approach that I hadn't thought of, thanks. I want to make sure I understand what is going on though.
I am providing the user the ability to add the textinput fields however they may not enter data into the fields until a short time later, so if I add the object to the ArrayCollection (when created) and the text fields are empty will the fields update in the ArrayCollection when the user inputs the text? or is what is stored in the ArrayCollection only a reference to the objects? Thanks. be well, Hoyt --- In [email protected], "Rick Winscot" <[EMAIL PROTECTED]> wrote: > > If you are finding it difficult to keep track of visual elements... there > isn't any reason that you couldn't use a helper - so you aren't crawling the > display list all the time looking for items that may or may not be there. > Obviously - this means that you have a little more house cleaning to do > in/out... but in your case it sounds like the benefits would out-weigh the > overhead. > > private var _collectionHelper:ArrayCollection = new ArrayCollection(); > > private function createTextSeries():void > { > for ( var i:int = 0; i < 10; i++ ) > { > var newTextInput:TextInput = new TextInput(); > newTextInput.text = "TextInput " + Math.random(); > > myContainer.addChild( newTextInput ); > _collectionHelper.addItem( newTextInput ); > } > } > > Then to loop through your dynamic components... is facilitated by the > _collectionHelper as: > > For each ( var target:TextInput in _collectionHelper ) > Trace("foo: " + target.text); > > Rick Winscot > > > From: [email protected] [mailto:[EMAIL PROTECTED] On > Behalf Of hoytlee2000 > Sent: Monday, April 21, 2008 6:39 PM > To: [email protected] > 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] <mailto:flexcoders%40yahoogroups.com> , > Lee <callistachan@> wrote: > > > > Hi, I replied below =) > > > > -- Lee > > > > ----- Original Message ---- > > From: hoytlee2000 <hoytlee2000@> > > To: [email protected] <mailto:flexcoders%40yahoogroups.com> > > 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 > > >

