2 Replies Latest reply on Apr 14, 2010 10:54 AM by luisborlido

    Check multiple checkboxes with similar id

    luisborlido Level 1

      Hi! I would like to know if it's possible to check multiple checkboxes with similar id. For example:

           <mx:Script>

                <![CDATA[

                     private function checkAllClickHandler(): void {
                          minute0.selected = true;
                          minute1.selected = true;
                          minute2.selected = true;
                          minute3.selected = true;
                          minute4.selected = true;
                          minute5.selected = true;
                          minute6.selected = true;
                          minute7.selected = true;
                          minute8.selected = true;

                     }

                ]]>

           </mx:Script>

       

           <mx:CheckBox id="minute0" label="00"/>
           <mx:CheckBox id="minute1" label="01"/>
           <mx:CheckBox id="minute2" label="02"/>
           <mx:CheckBox id="minute3" label="03"/>
           <mx:CheckBox id="minute4" label="04"/>
           <mx:CheckBox id="minute5" label="05"/>
           <mx:CheckBox id="minute6" label="06"/>
           <mx:CheckBox id="minute7" label="07"/>
           <mx:CheckBox id="minute8" label="08"/>

       

      There is a way of reducing the code? Thanks in advance.

        • 1. Re: Check multiple checkboxes with similar id
          oldMster Level 3

          Sure,

          Create the check boxes with actionscript instead of MXML, and keep the checkbox objects in an array, then you can just put them in a for loop.  If you want to keep them in mxml, then have a script in the 'creationcomplete' phase that does this:

           

          'above the line' variable declaration:

           

          private var checkboxes:Array;

           

          creationcomplete script:

           

          private function onCreationComplete():void {

               checkboxes = [minute0,minute1,minute2,minute3,minute4,minute5,minute6,minute7,minute8];

               for (var i=0; i++; checkboxes.length) {

                    checkboxes[i].selected = true; //to set them all true initially

               }

          }

           

          Mark

          • 2. Re: Check multiple checkboxes with similar id
            luisborlido Level 1

            Thanks for the help Mark!