1 Reply Latest reply on Apr 1, 2011 1:40 AM by CleanCoder

    how to change a labels text which created at runtime?

    imfromNeverland

      hi,

       

      i am creating label controls in runtime dynamically and adding them to a group component. this group component is in another custom component and i have lots of custom comp. in my app.

       

      my question is how can access (via id) and change a labels text whict created at runtime?

       

       

       

      i can change like this but i am setting id's and want to reach via id.

       

      var lbl:mx.controls.Label = mx.controls.Label(subMenu5.group_subMenu5.getElementAt(1));

      lbl.text = "good job";

       

      thank you, have a good day.

        • 1. Re: how to change a labels text which created at runtime?
          CleanCoder Level 2

          First off, if you are already using a Spark Group, I would suggest you use a Spark Label instead of an MX Label. If you want to reference the Labels from the group, loop through the group's elements and check the if the element id matches the Label you want to assign text to.

           

          var lbl:Label;

          var n:int = myGroup.numElements;

          for (var i:int = 0; i < n; i++)

          {

               lbl = myGroup.getElementAt(i) as Label;

               if (lbl && lbl.id == "myLabel")

               {

                    lbl.text = "newText";

               }

          }