7 Replies Latest reply on Oct 4, 2010 2:46 PM by Devtron

    Cycling through Tab's ....

    aktell2007 Level 1

      Hi there,

       

      Any help would be very much appriciated !!!

       

      When the Timer is finish auto cycling through the tabs (1 to 16) of this ViewStack, and switching over to tab (1) to STOP, I would like to address a function to do something???
      The question is now how to write the code to ID that the Timer has come to a STOP on tab (1), and how can I incoperate this into the existing (onTimerOne) function.

       

      <mx:Script>
      <![CDATA[
          import flash.events.TimerEvent;
          import flash.utils.Timer;

          private var timerOne:Timer;
               
          private function initOne():void {

              timerOne = new Timer(5000, myViewStack.numChildren);
              timerOne.addEventListener(TimerEvent.TIMER, onTimerOne);
          }
                                   
          private function onTimerOne(evt:TimerEvent):void {
                                   
              if(myViewStack.selectedIndex == myViewStack.numChildren-1) {
              myViewStack.selectedIndex = 0;
              return;
          }
              myViewStack.selectedIndex++;
          }

          private function autoOne():void {
              if (!timerOne.running) {
              timerOne.start();
              }
          }

          private function manualOne():void {
              if (timerOne.running) {
              timerOne.stop();
              }
          }
      ]]>
      </mx:Script>

       

      Thanks in advance aktell2007

        • 1. Re: Cycling through Tab's ....
          aktell2007 Level 1

          Anybody has an idea which I could make use off ???

          • 2. Re: Cycling through Tab's ....
            aktell2007 Level 1

            Anybody, ???

            • 3. Re: Cycling through Tab's ....
              BhaskerChari Level 4

              Hi aktell2007,

               

              I have not understood your question clearly. Can you be a bit more clear as what you want to acheive exactly.

               

              Thanks,

              Bhasker

              • 4. Re: Cycling through Tab's ....
                aktell2007 Level 1

                Well, finally somebody. Thanks a lot.

                 

                 

                When the Timer is finish auto cycling through the tabs (1 to 16) of this ViewStack, and switching over to tab (1) to STOP, I would like to address a function to do something???

                 

                My auto Timer when activated by a Btn. cycles through the Tab's (16) of my ViewStack and will come to a STOP on Tab (1) again !!!

                My question is how do I identify that the Timer with my code supplied has Stopped on Tab (1) and how could I use this to address it in a new function so that I can do something else with it. Say maybe just to 'Enable' some Btn's. etc.


                The question is now how to write the code to ID that the Timer has come to a STOP on tab (1), and how can I incoperate this into the existing (onTimerOne) function.

                • 5. Re: Cycling through Tab's ....
                  BhaskerChari Level 4

                   

                   

                  Hi aktell2007,

                   

                  You can make use of TimerEvent.TIMER_COMPLETE to acheive this...

                   

                  Check the sample code below:

                   

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                          layout="vertical"
                          verticalAlign="middle"
                          backgroundColor="white" creationComplete="initOne()">

                      <mx:Script>
                      <![CDATA[
                       import mx.controls.Alert;   
                       import flash.events.TimerEvent;   
                       import flash.utils.Timer;   
                      
                       private var timerOne:Timer;
                                    
                       private function initOne():void
                       {     
                        timerOne = new Timer(5000, myViewStack.numChildren);       
                        timerOne.addEventListener(TimerEvent.TIMER, onTimerOne);
                        timerOne.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);     
                       }                                 
                       private function onTimerOne(evt:TimerEvent):void
                       {                                     
                        if(myViewStack.selectedIndex == myViewStack.numChildren-1)
                        {       
                         myViewStack.selectedIndex = 0;       
                         return;   
                        }       
                        myViewStack.selectedIndex++;   
                       }
                       private function onTimerComplete(evt:TimerEvent):void
                       {

                            timerOne.stop();

                            timerOne.reset();  
                             Alert.show("Cycling through the Tabs complete.");

                      
                             // So here you come to know that the cycling is completed once and you can do here what ever logic you want to write
                             //callYourFunction();
                             //then again start your timer by calling autoOne(); function to start another cycle through the tabs
                       
                       }
                       private function autoOne():void
                       {       
                        if (!timerOne.running)
                        {       
                         timerOne.start();       
                        }    
                       }   
                       private function manualOne():void
                       {       
                        if (timerOne.running)
                        {       
                         timerOne.stop();       
                        }    
                       }
                       ]]></mx:Script>

                   

                    <mx:Button label="Start Cycling" click="timerOne.start()"/>
                    <mx:ViewStack id="myViewStack" selectedIndex="0" width="400" height="200">
                     <mx:VBox label="Box1" height="50" width="200">
                      <mx:Label text="Box1" />
                     </mx:VBox>
                     <mx:VBox label="Box2" height="50" width="200">
                      <mx:Label text="Box2" />
                     </mx:VBox>
                     <mx:VBox label="Box3" height="50" width="200">
                      <mx:Label text="Box3" />
                     </mx:VBox>
                     <mx:VBox label="Box4" height="50" width="200">
                      <mx:Label text="Box4" />
                     </mx:VBox>
                     <mx:VBox label="Box5" height="50" width="200">
                      <mx:Label text="Box5" />
                     </mx:VBox>
                     <mx:VBox label="Box6" height="50" width="200">
                      <mx:Label text="Box6" />
                     </mx:VBox>
                     <mx:VBox label="Box7" height="50" width="200">
                      <mx:Label text="Box7" />
                     </mx:VBox>
                     <mx:VBox label="Box8" height="50" width="200">
                      <mx:Label text="Box8" />
                     </mx:VBox>
                     <mx:VBox label="Box9" height="50" width="200">
                      <mx:Label text="Box9" />
                     </mx:VBox>
                     <mx:VBox label="Box10" height="50" width="200">
                      <mx:Label text="Box10" />
                     </mx:VBox>
                     <mx:VBox label="Box11" height="50" width="200">
                      <mx:Label text="Box11" />
                     </mx:VBox>
                     <mx:VBox label="Box12" height="50" width="200">
                      <mx:Label text="Box12" />
                     </mx:VBox>
                     <mx:VBox label="Box13" height="50" width="200">
                      <mx:Label text="Box13" />
                     </mx:VBox>
                     <mx:VBox label="Box14" height="50" width="200">
                      <mx:Label text="Box14" />
                     </mx:VBox>
                     <mx:VBox label="Box15" height="50" width="200">
                      <mx:Label text="Box15" />
                     </mx:VBox>
                     <mx:VBox label="Box16" height="50" width="200">
                      <mx:Label text="Box16" />
                     </mx:VBox>
                    </mx:ViewStack>
                         

                  </mx:Application>

                   

                  Thanks,

                  Bhasker

                  • 6. Re: Cycling through Tab's ....
                    aktell2007 Level 1

                    Well, BhaskerChari Thank you very much !!! Last night it got a little late for me here in NZ so just tried it out this morning.

                    You did made a real effort, great it works just fine.

                    • 7. Re: Cycling through Tab's ....
                      Devtron Level 3

                      Very cool!

                       

                      I can only imagine what a FLEX user group meeting in NZ would be like. We have 5 FLEX developers show up to our user group meetings in Austin, Texas and I was very surprised at the limited amount of FLEX developers in this city full of developers. Good luck mate!