7 Replies Latest reply on Aug 22, 2007 2:49 AM by mynameissam.co.uk

    Urgent! :Getting Actionscript to 'pause' - actionscript 2.0

    mynameissam.co.uk
      Hi guys,

      I need the actionscript to carry out a piece of code, then pause for 0.5 seconds, then carry out the next piece of code, then pause, then next code e.t.c

      There will be twenty pieces of code that build up an animation with tweens that need to start at different times.

      I guess its something to do with setInterval, but I'm not sure on the syntax, as there 20 pieces of code I don't want lots of nested code (though if thats the only way to do it then so be it!)

      I'd really appreciate your help guys

      cheers
        • 1. Re: Urgent! :Getting Actionscript to 'pause' - actionscript 2.0
          kglad Adobe Community Professional & MVP
          put your code blocks into function bodies and use setInterval() or setTimeout() to call those functions using the desired delay.
          • 2. Re: Urgent! :Getting Actionscript to 'pause' - actionscript 2.0
            mynameissam.co.uk Level 1
            Hey man, I'm not that clear. What do you mean by putting into function bodies? My code is:

            var mc1:Tween = new Tween(mc1, "_y", mx.transitions.easing.Bounce.easeOut, -20, 330, 20, false);

            mc1 will obviously change with each clip. How do I lay this out?
            • 4. Re: Urgent! :Getting Actionscript to 'pause' - actionscript 2.0
              mynameissam.co.uk Level 1
              sweet man. Ok I'm very tired so I need to clarify a few things :)

              Firstly, all this is going to take place on the first frame (and only frame) in an actionscript layer, so theres no button. Secondly, I'm familiar with onMotionFinished, but I want the second movie clip to start 0.5 seconds after the first one has STARTED not finished. It would take too long to wait until each one finished and the site vistor would get really bored :)

              I think we're nearly there though guys, all your help is much appreciated. I've though about using the setInterval function as I've used it before but the syntax seemed quite confusing for using multiple instances (remember I have 20 instances of the:

              var mc1:Tween = new Tween(mc1, "_y", mx.transitions.easing.Bounce.easeOut, -20, 330, 20, false);

              is there no way to do this:

              var mc1:Tween = new Tween(mc1, "_y", mx.transitions.easing.Bounce.easeOut, -20, 330, 20, false);

              stop;

              wait 0.5 seconds then

              var mc2:Tween = new Tween(mc2, "_y", mx.transitions.easing.Bounce.easeOut, -20, 330, 20, false);


              Or is it going to have to be more compicated :s

              thanks again
              • 6. Re: Urgent! :Getting Actionscript to 'pause' - actionscript 2.0
                mynameissam.co.uk Level 1
                cheers man, thats brilliant! So obviously I initialise all 20 of the var

                mC1:Tween = new Tween(mc1, "_y", mx.transitions.easing.Bounce.easeOut, -20, 330, 20, false); e.t.c

                at the start. Do I then need to put :mC2.stop(); and then mC3.stop(); or do I put

                mC3:Tween = new Tween(mc3, "_y", mx.transitions.easing.Bounce.easeOut, -20, 330, 20, false);

                between them?
                • 7. Re: Urgent! :Getting Actionscript to 'pause' - actionscript 2.0
                  mynameissam.co.uk Level 1
                  Ok, I've put it into my movie and the box2 drops perfectly after the first interval. However, instead of box falling after the second interval, box 2 keeps repeating its tween!

                  Its probably something very simple and I'm being rather stupid! Thanks for all your help, I wouldn't be reaching my deadline without your advice!

                  Heres the code:

                  import mx.transitions.easing.Bounce;
                  import mx.transitions.Tween;

                  //following code defines the tweens that control the boxes

                  //row 1
                  var drop1:Tween = new Tween(box1, "_y", mx.transitions.easing.Bounce.easeOut, -70, 330, 20, false);
                  var drop2:Tween = new Tween(box2, "_y", mx.transitions.easing.Bounce.easeOut, -70, 330, 20, false);
                  var drop3:Tween = new Tween(box3, "_y", mx.transitions.easing.Bounce.easeOut, -70, 330, 20, false);
                  var drop4:Tween = new Tween(box4, "_y", mx.transitions.easing.Bounce.easeOut, -70, 330, 20, false);
                  //row 2
                  var drop5:Tween = new Tween(box5, "_y", mx.transitions.easing.Bounce.easeOut, -70, 256, 16, false);
                  var drop6:Tween = new Tween(box6, "_y", mx.transitions.easing.Bounce.easeOut, -70, 256, 16, false);
                  var drop7:Tween = new Tween(box7, "_y", mx.transitions.easing.Bounce.easeOut, -70, 256, 16, false);
                  var drop8:Tween = new Tween(box8, "_y", mx.transitions.easing.Bounce.easeOut, -70, 256, 16, false);
                  //row 3
                  var drop9:Tween = new Tween(box9, "_y", mx.transitions.easing.Bounce.easeOut, -70, 182, 12, false);
                  var drop10:Tween = new Tween(box10, "_y", mx.transitions.easing.Bounce.easeOut, -70, 182, 12, false);
                  var drop11:Tween = new Tween(box11, "_y", mx.transitions.easing.Bounce.easeOut, -70, 182, 12, false);
                  var drop12:Tween = new Tween(box12, "_y", mx.transitions.easing.Bounce.easeOut, -70, 182, 12, false);
                  //row 4
                  var drop13:Tween = new Tween(box13, "_y", mx.transitions.easing.Bounce.easeOut, -70, 108, 8, false);
                  var drop14:Tween = new Tween(box14, "_y", mx.transitions.easing.Bounce.easeOut, -70, 108, 8, false);
                  var drop15:Tween = new Tween(box15, "_y", mx.transitions.easing.Bounce.easeOut, -70, 108, 8, false);
                  var drop16:Tween = new Tween(box16, "_y", mx.transitions.easing.Bounce.easeOut, -70, 108, 8, false);
                  //row 5
                  var drop17:Tween = new Tween(box17, "_y", mx.transitions.easing.Bounce.easeOut, -70, 34, 4, false);
                  var drop18:Tween = new Tween(box18, "_y", mx.transitions.easing.Bounce.easeOut, -70, 34, 4, false);
                  var drop19:Tween = new Tween(box19, "_y", mx.transitions.easing.Bounce.easeOut, -70, 34, 4, false);
                  var drop20:Tween = new Tween(box20, "_y", mx.transitions.easing.Bounce.easeOut, -70, 34, 4, false);

                  //stops the tweens from starting
                  drop2.stop();
                  drop3.stop();
                  drop4.stop();
                  drop5.stop();
                  drop6.stop();
                  drop7.stop();
                  drop8.stop();
                  drop9.stop();
                  drop10.stop();
                  drop11.stop();
                  drop12.stop();
                  drop13.stop();
                  drop14.stop();
                  drop15.stop();
                  drop16.stop();
                  drop17.stop();
                  drop18.stop();
                  drop19.stop();
                  drop20.stop();

                  onEnterFrame = function () {
                  drop1.start();
                  delete this.onEnterFrame;
                  };
                  drop1.onMotionStarted = function() {
                  myInterval = setInterval(pauseTween, 500);
                  function pauseTween() {
                  drop2.start();
                  clearInterval(myInterval);
                  }
                  };
                  drop2.onMotionStarted = function() {
                  myInterval = setInterval(pauseTween, 500);
                  function pauseTween() {
                  drop3.start();
                  clearInterval(myInterval);
                  }
                  };


                  Its probably soemthing to do with where I've put the second section. Any ideas?