Link to home
Create AccountLog in
Avatar of RakeshBhandari
RakeshBhandariFlag for India

asked on

How to read data from components having dynamically generated id


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,
ASKER CERTIFIED SOLUTION
Avatar of chrisP4D
chrisP4D
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of RakeshBhandari

ASKER

Thanks  chrisP4D,