3 Replies Latest reply on May 25, 2006 12:55 PM by eirkeirkeirk

    Wait code?

    Level 7
      Ok so i have this code:
      for (var i = 0; i < 400; ++i) {
      Small_mc._x = Small_mc._x + 1
      *
      }
      But i want it to wait for about 0.1 of a second *here
      Any help would be apprichated. Thanks

      From http://www.developmentnow.com/g/69_2004_10_0_1_0/macromedia-flash-actionscript.htm

      Posted via DevelopmentNow.com Groups
      http://www.developmentnow.com
        • 1. Re: Wait code?
          Ministoner
          Hi there, here a quick solution i whipped up, hope it helps.

          function moveMC(){
          if(counter >= 400){
          clearInterval(myInterval)
          }
          Small_mc._x += 1;
          counter++;
          }
          var counter:Number = 0;
          var myInterval:Number = setInterval(moveMC, 10);

          Basically it calls the function "MoveMC" every 0.1 seconds until it has called itslef 400 times (or which ever number you replace 400 with ) and then stops.

          Richard.
          • 2. Wait code?
            Level 1
            the problem with that code is that it will actually run through the entire loop before it redraws the screen. so instead of having your movie clip move across the screen, one pixel at a time, it will just jump 400 pixels.

            try something like this:

            var counter = 0;
            function mover() {
            if (counter < 0) {
            small_mc._++;
            counter++;
            } else {
            clearInterval(myInterval);
            }
            }

            setInterval("mover", 100);
            • 3. Re: Wait code?
              Level 1
              ha! you just beat me to it slightly different code, but same idea. and it's always nice to see more than one way to do the same thing

              erik