Solved

How to read data from components having dynamically generated id

Posted on 2010-11-13
4
699 Views
Last Modified: 2012-05-10

I have dynamically generated few components(TextBox) with dynamic ids.

Can anybody help me out about how to read data  from these dynamically generated Components.

following is my code:

//On every button click i m adding these components to my titlewindow by calling this function.
                  public function lnkAdd(event:Event):void
                  {
                        QuantityCount=QuantityCount+1;
                        
                        txtQuantityCount.text=QuantityCount.toString();
                        
                        //QuantityLabel
                        var lblQuant:Label=new Label();
                        lblQuant.id="lblQuantity"+QuantityCount+" :";
                        lblQuant.text="Quantity :";
                        lblQuant.x=20;
                        lblQuant.y=(lblQuantity1.y+(75*(QuantityCount-1)));
                        lblQuant.name=lblQuant.id;
                        QuantityGrp.addElement(lblQuant);
                        
                        
                        //Quantity TextBox
                        txtQuant=new TextInput();
                        txtQuant.id="txtQuantity"+QuantityCount;
                        //txtQuant.text=txtQuant.id.toString();
                        txtQuant.x=71;
                        txtQuant.y=(txtQuantity1.y+(75*(QuantityCount-1)));
                        txtQuant.restrict="0-9";
                        
                        QuantityGrp.addElement(txtQuant);
                        
                        
                        //lblMainLocation
                        var lblMainLoc:Label=new Label();
                        lblMainLoc.id="lblMainLocation"+QuantityCount+" :";
                        lblMainLoc.text="MainLocation :";
                        lblMainLoc.x=201;
                        lblMainLoc.y=(lblMainLocation1.y+(75*(QuantityCount-1)));
                        lblMainLoc.name=lblMainLoc.id;
                        QuantityGrp.addElement(lblMainLoc);
                        
                        
                        //MainLocation dropdownlist
                        ddlMainLoc=new DropDownList();
                        ddlMainLoc.id="ddlMainLocation"+QuantityCount;
                        //ddlMainLoc.labelDisplay.text=ddlMainLoc.id.toString();
                        ddlMainLoc.x=279;
                        ddlMainLoc.y=(ddlMainLocation1.y+(75*(QuantityCount-1)));
                        ddlMainLoc.dataProvider=Locations;
                        ddlMainLoc.requireSelection=true;
                        ddlMainLoc.labelField="MainLocation";
                        QuantityGrp.addElement(ddlMainLoc);
                        
                        
                        //lblSubLocation
                        var lblSubLoc:Label=new Label();
                        lblSubLoc.id="lblSubLocation"+QuantityCount+" :";
                        lblSubLoc.text="SubLocation :";
                        lblSubLoc.x=415;
                        lblSubLoc.y=(lblSubLocation1.y+(75*(QuantityCount-1)));
                        lblSubLoc.name=lblSubLoc.id;
                        QuantityGrp.addElement(lblSubLoc);
                        
                        
                        //SubLocation dropdownlist
                        ddlSubLoc=new DropDownList();
                        ddlSubLoc.id="ddlSublocation"+QuantityCount;
                        //ddlMainLoc.labelDisplay.text=ddlMainLoc.id.toString();
                        ddlSubLoc.x=489;
                        ddlSubLoc.y=(ddlSublocation1.y+(75*(QuantityCount-1)));
                        ddlSubLoc.dataProvider=Locations;
                        ddlSubLoc.requireSelection=true;
                        ddlSubLoc.labelField="SubLocation";
                        QuantityGrp.addElement(ddlSubLoc);
                        
                        //lblDescription
                        var lblDescript:Label=new Label();
                        lblDescript.id="lblDescription"+QuantityCount+" :";
                        lblDescript.text="Description :";
                        lblDescript.x=613;
                        lblDescript.y=(lblDescription1.y+(75*(QuantityCount-1)));
                        QuantityGrp.addElement(lblDescript);
                        
                        
                        //Description textbox
                        txtDescript=new spark.components.TextArea();
                        txtDescript.id="txtDescription"+QuantityCount;
                        //txtDescript.text=txtDescript.id.toString();
                        txtDescript.x=678;
                        txtDescript.width=226;
                        txtDescript.height=59;
                        txtDescript.y=(txtDescription1.y+(75*(QuantityCount-1)));
                        QuantityGrp.addElement(txtDescript);
                        
                        
                        //lblDepartment
                        var lblDepart:Label=new Label();
                        lblDepart.id="lblDepartment"+QuantityCount+" :";
                        lblDepart.text="Department :";
                        lblDepart.x=6;
                        lblDepart.y=(lblDepartment1.y+(75*(QuantityCount-1)));
                        
                        QuantityGrp.addElement(lblDepart);
                        
                        
                        //Department dropdownlist
                        ddlDepart=new DropDownList();
                        ddlDepart.id="ddlDepartment"+QuantityCount;
                        //ddlMainLoc.labelDisplay.text=ddlMainLoc.id.toString();
                        ddlDepart.x=71;
                        ddlDepart.y=(ddlDepartment1.y+(75*(QuantityCount-1)));
                        ddlDepart.dataProvider=Departments;
                        ddlDepart.requireSelection=true;
                        ddlDepart.labelField="DeptName";
                        QuantityGrp.addElement(ddlDepart);
                        
                        
                        //lblUsers
                        var lblUser:Label=new Label();
                        lblUser.id="lblUsers"+QuantityCount+" :";
                        lblUser.text="Users :";
                        lblUser.x=229;
                        lblUser.y=(lblUsers1.y+(75*(QuantityCount-1)));
                        QuantityGrp.addElement(lblUser);
                        
                        
                        //Department dropdownlist
                        ddlUser=new DropDownList();
                        ddlUser.id="ddlUsers"+QuantityCount;
                        //ddlMainLoc.labelDisplay.text=ddlMainLoc.id.toString();
                        ddlUser.x=278;
                        ddlUser.y=(ddlUsers1.y+(75*(QuantityCount-1)));
                        QuantityGrp.addElement(ddlUser);
                        
                  }

As the ids are in string format i am not able to call it's(Textbox) text  property to get their values.


Help appreciated,
0
Comment
Question by:RakeshBhandari
4 Comments
 
LVL 3

Accepted Solution

by:
chrisP4D earned 500 total points
ID: 34139005
i was working on something similar earlier this week.  basically what you could do is loop through the parent containers children and display your data dynamically.

var tmp:String = '';
for each (var childButton in qtrHolder.getChildren()){
                        
                                    Alert.show(childButton.id);
                        
                                    for each (var childButton2 in childButton.getChildren()){
                                          if(childButton2 is quarterRenderer){
                                          tmp = tmp+'\n'+childButton2.yr+'-'+childButton2.qtr+': '+childButton2.qtrValue.text;
                                          }
                                    }
                                    Alert.show(tmp);
                        }

to explain the code above, qtrHolder is a VBox i have with some dynamically created HBox components.  the HBox holds a couple labels and a textinput field.

the first loop runs through the main VBox's children and returns all my HBoxs and shows an Alert with every HBoxs ID.

the second loop runs through all of the HBox children.  it does a check to see if the child is a quarterRenderer (a custom component i made but you would use whatever container you have) and then displays the 2 string variables and the textinput boxes value. (yr and qtr are strings and qtrValue is a textinput )

this might look confusing, but let me know if it helps.  i probably did an awful job explaining it, but i believe this is what you're trying to do.
0
 
LVL 2

Author Comment

by:RakeshBhandari
ID: 34142692
Thanks  chrisP4D,

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
API Soap Calls 4 91
connect a series of circles by line based on clicks 4 52
modify h2 4 89
Angular2 app not loading Bootstrap properly 4 12
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now