1 Reply Latest reply on Mar 8, 2012 5:21 PM by drkstr_1

    Accessing elements created at run time

    Zolotoj Level 3

      Somewhere in my code I am dealing with my elements in the following way:

      child.hasOwnProperty("id") && Object(child).id != null

      but elements added with addElement do not have an ID. Is there to access these elements without specifying the ID?

       

      Thanks

        • 1. Re: Accessing elements created at run time
          drkstr_1 Level 4

          For starters, I probably wouldn't use the first method you described at all. It is much better to reference the instance directly than to "search" for it using strings. That being said, for dynamic content, you can actually assign a string ID to a component, or a name if you so choose, and use that string value to "search" for your instance. In most cases though, it's better to just write some code that allows you to reference any elements you're interested in directly.

           

          For example:

           

          private var _labelElements:Array = [];
          
          private function addText(label:Label):void
          {
               this.someChildContainer.addElement(label);
          
               //save the label in an array so we can loop through
               //all the labels at any given time
               _labelElements.push(label);
          }
          

           

          It's hard to give specific advice without knowing anything about what you are trying to accomplish in the end.