3 Replies Latest reply on Jul 29, 2009 12:42 AM by Virat Patel

    execute a command after 3 seconds...

    jonatasmz

      hey guys... there´s a way on AS to execute a command like.... menu2items.selectedIndex = 2; after some seconds?

       

      cya....

        • 1. Re: execute a command after 3 seconds...
          BennyBeta Level 4

          Yes, use a Timer.

           

          http://www.flexafterdark.com/docs/ActionScript-Timer

           

          Let me know if that helps...

           

          Ben Edwards

          1 person found this helpful
          • 2. Re: execute a command after 3 seconds...
            BennyBeta Level 4

            Example code:

             

            import flash.utils.Timer;
            import flash.events.TimerEvent;

            // create a timer that executes after 3 seconds, only once
            public var timer:Timer = new Timer( 3*1000, 1 );
                    
            public function init():void
            {
                 // add event listeners
                 timer.addEventListener( TimerEvent.TIMER, handleTimerEvent );
                       
                 // start the timer
                 timer.start();
            }
                    
            public function handleTimerEvent( event:TimerEvent ):void
            {
                 menu2items.selectedIndex = 2;
            }

             

            Let me know if that helps...

             

            Ben Edwards

            • 3. Re: execute a command after 3 seconds...
              Virat Patel

              Hello

               

              Check this code

               

                   private var intervalIndex : uint;
                             
                   intervalIndex = setInterval(callAfterSomeTime,2000); // set function closure and interval

                   // setInterval method runs a function at a specified interval in milliseconds.

               

                   private function callAfterSomeTime():void
                   {
                        // do something

                        menu2items.selectedIndex = 2;
                        clearInterval(intervalIndex);

                  }

               

              may help you.   

               

              With Regard

              Virat Patel

              1 person found this helpful