1 Reply Latest reply on May 30, 2007 4:43 PM by boxdoctor

    Cycling through components

    Dan_Herbison
      I'm new to flex and wonder if someone could give me a hint or show me how to gain access to a undefined number of similar UI components. I'm trying to write my first component and want all the components, of this type, to work together. So if an event occurs on one of the components it may affect the others. How do I cycle through all the components in an application to find components of a like type without knowing before hand how many there are????
        • 1. Re: Cycling through components
          boxdoctor
          Yikes.....I did something like this in Flash AS2.0, so I don't know if it will work, but I'm sure the concept is about the same. Basically if you use a good naming convention (back then it was suffixes like _cb, _txt, etc.), this enabled you to loop through all of the UI's (in this case my checkboxes) and see if they were checked or not. You can try it and maybe just trace out the results to see if it gives you what you want. Cheers!!!

          //Check all of the cb's
          for (var i:String in this)
          {
          if (i.indexOf("_cb") != -1)
          {
          if (i.indexOf("Start_cb", 0) == -1)
          {
          if (i.indexOf("End_cb", 0) == -1)
          {
          //Ok so let's see if index 0 is selected...if so throw an error
          if ((this .selectedIndex == 0) && (i != "screenModify_cb"))
          {
          //NetDebug.trace("whoops you didn't select anything here");
          Alert.show("Please make sure all required (*) fields are selected or filled out completely.", "Screen Add/Modify Error");
          process = 0;
          break;
          }
          }
          }
          }
          }