Arrrr. ye forgot -
o as Foo //latent type casting Rick Winscot From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Gordon Smith Sent: Wednesday, April 23, 2008 4:23 PM To: [email protected] Subject: RE: [flexcoders] Re: how do I loop thru dynamically created UI components? When you cast like this var foo:Foo = Foo(whatever); the syntax looks like a constructor-without-the-'new', but it actually has nothing to do with a constructor. The name of a class can be used in various unrelated ways: new Foo() // constructs an instance of Foo Foo(o) // casts o to type Foo o = Foo // sets o to a reference to class Foo Gordon Smith Adobe Flex SDK Team _____ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of hoytlee2000 Sent: Wednesday, April 23, 2008 1:31 AM To: [email protected] Subject: [flexcoders] Re: how do I loop thru dynamically created UI components? Hello Lee, Thanks! that typecasting line worked perfectly! It's interesting I tried to import just the HBox specifically and I still got the error message in the IDE as: Implicit coercion of a value with static type flash.display:DisplayObject to a possibly unrelated type mx.containers:HBox. If I read the line correctly, I can TypeCast a Display Object by using the constructor of the UIComponent? Thanks, hoyt --- In [email protected] <mailto:flexcoders%40yahoogroups.com> , Lee <[EMAIL PROTECTED]> wrote: > > > hmm that's odd... i'm coding a project right now and that's what i use... but i don't import everything (*)... hehe > anyway, if you want typecasting, i usually do something like this: > > var str:String = TextInput(HBox(vbox.getChildAt(i)).getChildAt(1)).text; > > let me know if it's not still working and i'll try to figure it out :) > > -Lee > > ----- Original Message ---- > From: hoytlee2000 <[EMAIL PROTECTED]> > To: [email protected] <mailto:flexcoders%40yahoogroups.com> > Sent: Wednesday, April 23, 2008 3:04:29 PM > Subject: [flexcoders] Re: how do I loop thru dynamically created UI components? > > 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] <mailto:flexcoders%40yahoogroups.com> , Lee <callistachan@> wrote: > > > > did you import them? > > > > ----- Original Message ---- > > From: hoytlee2000 <hoytlee2000@> > > To: [email protected] <mailto:flexcoders%40yahoogroups.com> > > 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] <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 > > > > > > > > > > > ------------------------------------ > > > > -- > > 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 >
<<image001.jpg>>
<<image002.jpg>>

