2 Replies Latest reply on Jul 5, 2007 8:50 AM by sr817

    Pausing code for a certain amount of time

    sr817
      I had a question that I hope someone would be able to answer. Is there a way to pause code, leaving a set amount of time between when one line of code is executed and when the next line of code is called? I'm assuming there is atleast one way to do it, but I'm still very new to actionscript and confused by some of it's syntax. I've seen other posts of this nature, but all of them for older versions of flash and prior versions of actionscript. Can anyone help, possibly providing an example of such code for flash CS3 and actionscript 3.0 (or 2.0 as I'm still not clear what the differences are between the 2.0 and 3.0)?

      Thanks,
      Sam
        • 1. Re: Pausing code for a certain amount of time
          yarkehsiow
          hi

          stop();
          intID = setInterval(delay, 3000); //this tells flash to wait 3 seconds
          function delay(){
          clearInterval(intID);
          _root.gotoAndPlay(1); // or do something else...
          };

          hope this helps...its a very useful script for me, but perhaps someone has something better for you...
          • 2. Re: Pausing code for a certain amount of time
            sr817 Level 1
            hey yarkehsiow,
            Thank you so much for the fast response. This code looks wonderful and I'm grateful for your help, but I'm running into a few errors in the code.

            Here is what my simple code looked like before trying your code:

            import flash.display.*;
            import flash.events.*;
            import flash.display.MovieClip;
            stop();
            btmbtna.booksbtna.addEventListener(MouseEvent.MOUSE_DOWN, startBooks);

            function startBooks(e:MouseEvent): void {
            topbtna.gotoAndPlay(1);
            midbtna.gotoAndStop(1);
            }


            The updated code I tried two different ways with the same results:

            import flash.display.*;
            import flash.events.*;
            import flash.display.MovieClip;
            stop();
            btmbtna.booksbtna.addEventListener(MouseEvent.MOUSE_DOWN, startBooks);

            function startBooks(e:MouseEvent): void {
            topbtna.gotoAndPlay(1);
            stop();
            intID = setInterval(delay, 3000); //this tells flash to wait 3 seconds
            function delay(){
            clearInterval(intID);
            midbtna.gotoAndStop(1); // or do something else...
            }
            }

            and/or

            import flash.display.*;
            import flash.events.*;
            import flash.display.MovieClip;
            stop();
            btmbtna.booksbtna.addEventListener(MouseEvent.MOUSE_DOWN, startBooks);

            intID = setInterval(delay, 3000); //this tells flash to wait 3 seconds
            function delay(){
            clearInterval(intID);
            midbtna.gotoAndStop(1); // or do something else...
            }

            function startBooks(e:MouseEvent): void {
            topbtna.gotoAndPlay(1);
            stop();
            delay();
            }

            When I added your code into my script in both ways (remembering to change _root to my root object, etc.), I ran into two errors: their descriptions read "access of undefined property IntID. The error source for one was "IntID = setInterval(delay, 3000)" and the other was "clearInterval(intID)". I can guess what these error messages mean, but in reality, I'm not sure how to address them. You've already helped enough, but could someone explain what I'm doing wrong here?