3 Replies Latest reply on Mar 31, 2008 1:06 PM by curtkauf

    Looping Through Container Controls

    curtkauf Level 1
      I have a panel with over 50 controls on it. I want to loop through all of the TextInput controls and set their text property to "". I don't see how to do that with Flex. I see how to get to the controls:

      var numChildren = pnRates.numChildren;

      for (var i:int = 0; i < numChildren; i++) {
      if(pnRates.getChildAt(i) is TextInput"){

      }

      however I don't understand how to access the controls properties from here. Any help will be greatly appreciated. Thanks!

      curtkauf
        • 1. Looping Through Container Controls
          cxf02 Level 1
          Use the myChildObjects = this.getChildren() method to return an array of child objects from a Panel, then iterate through the array using dot notation myChildObjects[ i ].text to access each object's text attribute.

          It's all about containers within containers. Each array element holds a reference to an instance of a child object. You may need to check the data type of each child to make sure it's a text object as well. You would do this by: if ( myChildObjects[ i ] as TextInput ) myChildObjects[ i ].text = "";

          Try that...
          • 2. Re: Looping Through Container Controls
            Mitek17 Level 1
            E.g.:

            var aChildren:Array = pnRates.getChildren();;
            for (var i:uint = 0; i < aChildren.length; i++)
            {
            if (aChildren is TextInput)
            {
            TextInput(aChildren
            ).text = "";
            }
            }
            • 3. Re: Looping Through Container Controls
              curtkauf Level 1
              I altered yours just a bit to include the index of the object

              var aChildren:Array = pnRates.getChildren();;
              for (var i:uint = 0; i < aChildren.length; i++)
              {
              if (aChildren is TextInput)
              {
              TextInput(aChildren
              ).text = "";
              }
              }

              Thank you! it works perfectly now!!!

              Curt