Solved

How to read data from components having dynamically generated id

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This video teaches users how to migrate an existing Wordpress website to a new domain.

743 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

12 Experts available now in Live!

Get 1:1 Help Now