Solved

How to read data from components having dynamically generated id

Posted on 2010-11-13
4
700 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Read about why website design really matters in today's demanding market.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
The viewer will learn how to count occurrences of each item in an array.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

770 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