?
Solved

How to read data from components having dynamically generated id

Posted on 2010-11-13
4
Medium Priority
?
704 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Accepted Solution

by:
chrisP4D earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

762 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