6 Replies Latest reply on Jan 18, 2010 2:49 PM by ahrimanes6x3

    For each  multyple components of the same type?

    ahrimanes6x3

      Hy, thats it, im traying to figure out how to set text property of a bunch of componets that are all the same type in blank but i wont do it like this:

       

      [CODE]comboBox1.text = "";

      comboBox2.text = "";
      comboBox3.text = "";
      comboBox4.text = "";
      comboBox5.text = "";[/CODE]

       

      i want to do somthing like this:

       

      [CODE]for each(var combo as combobox) in this{
               combo.text = "";
      }
      [/CODE]

       

      this piese of code is just a ficcion just for u to get the idea of what i want to do, obeusly it dont work this way.

       

      TNKSSSSSS....

        • 1. Re: For each  multyple components of the same type?
          Gregory Lafrance Level 6

          It was really hard to understand exactly what you wanted, but maybe this answers your question:

           

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
            <mx:Script>
              <![CDATA[
                import mx.controls.Text;
                
                private function init():void{
                  for(var a:uint=1;a<7;a++){
                    this["text" + a].text = "reset";
                  }
                }
              ]]>
            </mx:Script>
            <mx:Button label="Reset" click="init();"/>
            <mx:Text id="text1" text="one"/>
            <mx:Text id="text2" text="two"/>
            <mx:Text id="text3" text="three"/>
            <mx:Text id="text4" text="four"/>
            <mx:Text id="text5" text="five"/>
            <mx:Text id="text6" text="six"/>
          </mx:Application>
          

           

          If this post answers your question or helps, please mark it as such.


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          Flex / AIR Development, Training, and Support Services

          1 person found this helpful
          • 2. Re: For each  multyple components of the same type?
            ahrimanes6x3 Level 1

            hiii im glad you answerd this has open my eyes, now all i have to do is to put all my control names in to an array "this bringme a litle more control over the components i need to be reset" soo i can use your for. its alitle more complex than i xpected but it will work. thank you very much.

            • 3. Re: For each  multyple components of the same type?
              ahrimanes6x3 Level 1

              hooo well it work but i have a problem here...

               

              all the components i need to reset are in an state called state2 and when I change the state from state1 to state 2 I need the controls to be reset so i do this:

               

                      private function toggleStates():void{
                          switch (currentState) {
                              case "state1":
                                  currentState = "state2";
                                  setAllBlank();
                                 
                                  break;
                              case "state2":
                                  currentState = "state1";
                                  break;
                              default:
                                  currentState = "state1";
                                     break;
                          }

               

              where setAllBlank is:

               

                      private function setAllBlank():void{
                          for(var a:uint=0;a<myDoubleComboBox.length;a++){
                                this[myDoubleComboBox[a]].CBClave.text = "";
                                this[myDoubleComboBox[a]].CBDesc.text = "";
                          }

                     }

               

              well it work with no errors but i dont see the changes until the second time.. I mean i can only see the changes if i go back to state 1 an then  again state2.

               

              hope there is  a way to solve it.

              tnks...

              • 4. Re: For each  multyple components of the same type?
                ahrimanes6x3 Level 1

                hamm well i think i have solved the issue in a very carvern way....

                 

                at the creationcomplete event I call an init function, in the very begining of this fucntion I set the current state to state2 then to state1, that makes the states to an arcaic preload... so when I run the function to reset all my controls it works...

                now the question is "is there a way to plreload all the views by a function or sonthing no the way I did?"...

                tnks...

                • 5. Re: For each  multyple components of the same type?
                  Gregory Lafrance Level 6

                  Try this:

                   

                  private function toggleStates():void{
                      switch (currentState) {

                           case null:
                           case "state1":
                                currentState = "state2";
                                setAllBlank();
                                break;
                           case "state2":
                                currentState = "state1";
                                break;
                           default:
                                currentState = "state1";
                                break;
                  }

                   

                  If this post answers your question or helps, please mark it as such.


                  Greg Lafrance - Flex 2 and 3 ACE certified

                  www.ChikaraDev.com

                  Flex / AIR Development, Training, and Support Services