1 Reply Latest reply on Mar 24, 2010 9:45 AM by skider

    How to get dynamically added components

    Raghuvasa Level 1

      Hi,

       

          i am adding panels to canvas  dynamically. while adding panels i am specifying the id's for the panels.

       

      now i need to set  the header colors to dynamically added panels. but i am not able to get the dynamically added components.

       

      how can i get the components. and how can i set the  headerColors to that panels.

       

      can any one help me?

       

       

       

      thanks

      Raghu.

        • 1. Re: How to get dynamically added components
          skider Level 1

          When you set an id in MXML, it is specially processed so that you can access the component by that id. This process does not take place when you are defining components in ActionScript.

           

          There are a couple of things that you can do to find the components in ActionScript. First, you could declare them as variables inside the scope of the object, rather than in your method. This would allow you to refer to the components by their variable.

           

          Second, you could give the component a name (set component.name), and use the container's getChildByName method to locate the component when you need it.

           

          Third, you could create an array (probably an associative one, e.g. a Dictionary), and add the components to that array as you create them. Then you could pull those components out of the array when you need to reference them.

           

          Hopefully this helps.