6 Replies Latest reply on Dec 21, 2009 12:26 PM by pir897

    Help looping states with a timer

    pir897

      When the timer fires I need to move to the next state.  Is there an easy way to tell it to go to the next state or do I have to determine the current state and define the next state?

       

      If I have to go the second route how would that be coded?

       

      private function onTimer(evt:TimerEvent):void
                  {
                    if (currentState == 'lifeSciences')

                       <!--   how do I tell it to make 'lifestyle' the new state? -->
                  }

        • 1. Re: Help looping states with a timer
          saisri2k2 Level 4

          if you do this.states ... you will get an array of states. So, I would do like this

           

          //The followin are the global values

          public var counter:int = 0;

          public var states:Array;

           

          private function onTimer(evt:TimerEvent):void
                      {
                             if(states == null)states = this.states;

           

                              if(counter!=states.length){

                                   counter++;

                                  }

           

                              else{

                                        counter = 0;

           

                                  }

           

                                this.currentState = states[counter].name;                   

                      }

          • 2. Re: Help looping states with a timer
            pir897 Level 1

            I'm getting an error on public var states:Array;

             

            1152: A conflict exists with inherited definition mx.core:UIComponent.states in namespace public.

             

            It is good to know that I can use an array rather than naming each state in the AS.

            • 3. Re: Help looping states with a timer
              saisri2k2 Level 4

              Change the array name to something else.. Some errors might throw as i've not typed thta in the eclipse.. i've just gave a outline of how it should be like..

              • 4. Re: Help looping states with a timer
                pir897 Level 1

                Forgive the extra questions, but if I change my array name from states to myStates do I replace all of the instances of states with myStates?  I get easily confused

                 

                public var counter:int = 0;
                            public var myStates:Array;
                            
                            private function onTimer(evt:TimerEvent):void
                            {
                                if(states == null)states = this.states;
                                
                                if(counter!=states.length)
                                {
                                    counter++;
                                }
                                    
                                else
                                {
                                    counter = 0;
                                    
                                }
                                
                                this.currentState = states[counter].name;                   
                            }

                • 5. Re: Help looping states with a timer
                  saisri2k2 Level 4

                  except 'this.states' every thing should be your custom name(myStates)... i'm tlking about the following line.. sorry for writing the code soo confusing..

                   

                    if(states == null)states = this.states;

                  • 6. Re: Help looping states with a timer
                    pir897 Level 1

                    It works!  Thank you so much.