5 Replies Latest reply on Aug 19, 2009 2:49 PM by Gregory Lafrance

    Any sleep/pause/wait function in flex/AS

    AmitVyawahare Level 1

      I am new to flex and this forum. So can anyone tell me how to produce a delay in my program. I just need 3 second delay in my program.

      I just need to write a delay function. The function look like..

       

      private function delay():void

      {

           // 3 second delay code

      }

       

      Thank you,

      --Amit

        • 2. Re: Any sleep/pause/wait function in flex/AS
          AmitVyawahare Level 1

          I tryed this stuff before but i am not able to get that delay. I think i am doing some thing wrong. It will not take more than 3 line of code to create delay.

          Can you please code for me. thank you.

           

          --Amit

          • 3. Re: Any sleep/pause/wait function in flex/AS
            Gregory Lafrance Level 6

            If this post answered your question or helped, please mark it as such.

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
              creationComplete="init();">
              <mx:Script>
                <![CDATA[
                  private var myTimer1:Timer;
                  private var myTimer2:Timer;
                  [Bindable] private var num1:uint = 0;
                  [Bindable] private var num2:uint = 0;

                  private function init():void{
                    myTimer1 = new Timer(3000, 1);
                    myTimer1.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler1);
                    myTimer1.start();
                    myTimer2 = new Timer(1000, 0);
                    myTimer2.addEventListener(TimerEvent.TIMER, timerHandler2);
                    myTimer2.start();
                  }

                  public function timerHandler1(event:TimerEvent):void {
                    num1++;
                  }

                  public function timerHandler2(event:TimerEvent):void {
                    num2++;
                  }
                ]]>
              </mx:Script>
              <mx:Label id="lbl_1" fontSize="40" text="{String(num1)}"/>
              <mx:Label id="lbl_2" fontSize="40" text="{String(num2)}"/>
            </mx:Application>

            1 person found this helpful
            • 4. Re: Any sleep/pause/wait function in flex/AS
              AmitVyawahare Level 1

              This is helpful but problem is how do i know when that 3 second will finish.

               

              private var myTimer1:Timer;

              [Bindable] private var num1:uint = 0;

                    private function init():void{

                      myTimer1 = new Timer(3000, 1);

                      myTimer1.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler1);

                      myTimer1.start();

                    }

                    public function timerHandler1(event:TimerEvent):void {

                      num1++;

                    }

               

              I want to insert a function when that 3 second finish. The function name is check(). Where should i put this check function.

              My aim is when that 3 second finish i want to call check() function.

               

              --AMit

              • 5. Re: Any sleep/pause/wait function in flex/AS
                Gregory Lafrance Level 6

                If this post answered your question or helped, please mark it as such.

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                  creationComplete="init();">
                  <mx:Script>
                    <![CDATA[
                      private var myTimer1:Timer;

                      private function init():void{
                        myTimer1 = new Timer(3000, 1);
                        myTimer1.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler1);
                        myTimer1.start();
                      }

                      public function timerHandler1(event:TimerEvent):void {
                        check();
                      }

                      public function check():void {
                        lbl_1.text = "check() function called.";
                      }
                    ]]>
                  </mx:Script>
                  <mx:Label id="lbl_1" fontSize="40" text="waiting"/>
                </mx:Application>