8 Replies Latest reply on Jul 23, 2006 9:46 PM by flashfloozie

    time delays

    Lordy_UK
      Is there a way to create a short time delay within actionscript coding?

      i.e. a line of actionscript is executed, then a pause of however many seconds, then execute the next line of actionscript
        • 1. Re: time delays
          Level 7
          "Lordy_UK" <webforumsuser@macromedia.com> wrote in message news:e9tjoa$399$1@forums.macromedia.com...
          > Is there a way to create a short time delay within actionscript coding?
          >
          > i.e. a line of actionscript is executed, then a pause of however many seconds, then execute the next line of actionscript

          setIntervals can be used.

          textBox.text = "the first thing happened here";
          id = setInterval(nextThing, 2000); // do something 2 seconds from now

          function nextThing()
          {
          clearInterval(id);
          textBox.text = "the next thing has happened now";
          id = setInterval(anotherThing, 2000); // in 2 more seconds, do this call
          }

          function anotherThing()
          {
          clearInterval(id);
          textBox.text = "now another thing has happened";
          id = setInterval(moreThings, 5000); // in 5 more seconds call this one
          }

          function moreThings()
          {
          clearInterval(id);
          textBox.text = "more things have happened";
          }

          HTH
          tralfaz


          • 2. time delays
            kalibahlutwo
            You can use the setInterval() function or you can just do it with this frame script.

            waittime = gettimer() + 1000; // or however many milliseconds you want
            while (waittime > gettimer()) {
            stop();
            }
            play();

            • 3. Re: time delays
              Level 7
              "kalibahlutwo" <webforumsuser@macromedia.com> wrote in message news:e9tqn8$aug$1@forums.macromedia.com...
              > You can use the setInterval() function or you can just do it with this frame script
              >
              > while (waittime > gettimer()) {
              > stop();
              > }
              > play();

              Please test your code.
              tralfaz


              • 4. time delays
                kalibahlutwo Level 1
                tralfaz , sorry to throw you off there, if you look again, my code is fine. In fact, I copied it from the movie I'm currently working on where it works like a charm. You just happened to reply in the less-than-2-minute gap when I edited and pasted in the part I forgot to copy out of the movie the first time. :)
                • 5. Re: time delays
                  Level 7
                  "kalibahlutwo" <webforumsuser@macromedia.com> wrote in message news:e9ucts$14d$1@forums.macromedia.com...
                  > tralfaz , sorry to throw you off there, if you look again, my code is fine. In
                  > fact, I copied it from the movie I'm currently working on where it works like a
                  > charm. You just happened to reply in the less-than-2-minute gap when I edited
                  > and pasted in the part I forgot the copy out of the movie the first time. :)

                  When you edit your post on the forum, the changes don't get sent to the newsgroup. The newsgroup only sees your original post. The
                  newsgroup version of the forum is where the majority of regular posters post from and read from because the forum is just too
                  erratic and sluggish to use every day. Oh well, no big thing.
                  tralfaz


                  • 6. Re: time delays
                    kalibahlutwo Level 1
                    Yikes! I didn't know that! So, it *never* updates on the newsgroup??? Well, thank you for letting me know... here's the code again for newsgroup users:

                    waittime = gettimer() + 1000; // or however many milliseconds you want
                    while (waittime > gettimer()) {
                    stop();
                    }
                    play();
                    • 7. Re: time delays
                      Level 7
                      "kalibahlutwo" <webforumsuser@macromedia.com> wrote in message news:ea0jmv$guo$1@forums.macromedia.com...
                      > Yikes! I didn't know that! So, it *never* updates on the newsgroup??? Well,
                      > thank you for letting me know... here's the code again for newsgroup users:
                      >
                      > waittime = gettimer() + 1000; // or however many milliseconds you want
                      > while (waittime > gettimer()) {
                      > stop();
                      > }
                      > play();

                      Even though that code does stop the timeline for one second, it also halts EVERYTHING else in the project too, not just the
                      timeline. It halts all other movieclips and actions all through the project. You are bringing the entire project to a halt while
                      you sit in that frame. You should never sit in a while loop for more than one frame cycle.

                      You can change your code a little bit so that it works the way real-time coding is designed to work. You can check your elapsed
                      time, then get out until the next frame where you then come back and check the elapsed time again.

                      stop();
                      waittime = gettimer() + 1000; // or however many milliseconds you want
                      this.onEnterFrame = function()
                      {
                      if(gettimer() > waitTime)
                      {
                      delete this.onEnterFrame;
                      play();
                      }
                      }

                      When you do it this way you can use as long of a delay as you want without causing an error condition.
                      Then end result works about the same as a setInterval so it doesn't matter which you use but a while loop isn't a good choice.
                      tralfaz


                      • 8. Re: time delays
                        flashfloozie Level 1
                        There is a timer component that works great. It is by Lacaris Components. A google ought to find it.

                        ff