6 Replies Latest reply on Sep 18, 2007 1:56 AM by s83g1000

    Can you pause your actionscript?

      Hi All

      I am just wondering if you can pause the execution of your code, for example: I run some code, the code pauses for 3 seconds when it hits a certain line and then continues running. If anyone knows perl I am looking for something like the 'sleep' function.

      The reason is that I have a motion tween that is done in actionscript, once the tween is finished I need to set additional properties to the tweened object, but only once the tween is finished so I need the code to wait a few seconds.

      Any help would be appreciated.

        • 1. Re: Can you pause your actionscript?
          s83g1000 Level 1
          Never mind, I can use setInterval()

          • 2. Re: Can you pause your actionscript?
            Greg Dove Level 4
            In as2, from flash 8 onwards (I don't think it was available before flash 8) you can also use setTimeout() which is more like what you want.

            setTimeout is a single delayed call. setInterval is a repeated delayed call - so using setInterval you need to cancel it after the first call to prevent repeats.

            If you get a compiler error with setTimeout in flash8 its because it was omitted from the original intrinsic class definitions. But it is there and is available from player 8, so that can be fixed by adding it to the intrinsic class files.
            • 3. Re: Can you pause your actionscript?
              its very simple, all you need to do is, be like Hiro in Heroes, and have the special ability to stop time, and with that, you can have your delay of 3 seconds, but of course, the user probably wont notice because the user's time is stopped also.
              therefore, the simplier solution is still..... maybe to use setInterval
              • 4. Re: Can you pause your actionscript?
                clbeech Level 3
                @GWD: nice with the setTimeout.

                @s83g1000: why don't you use 'tween.onMotionFinished' to set your new parameters and fire the next code sequence?
                • 5. Re: Can you pause your actionscript?
                  s83g1000 Level 1
                  Thanks for the help.

                  I haven't looked at tween.onMotionFinished yet, I will check this out.

                  • 6. Re: Can you pause your actionscript?
                    s83g1000 Level 1
                    Hi again

                    I am still having problems with this. Basicly what I am trying to do is create a tween for my menu to roll down when the mouse hovers over it. The menu content is loaded dynamically so the tween also needs to be. I have got the code working in the way that I want ti to but there is still one more problem, I want to place the whole block of code inside an IF statement so the code doesn't run again if the menu is out, but when inside the IF statement the function does not run! My code is below, any suggestions would be appreciated! Thanks

                    if(_global.ProStatus != "Out"){
                    var intervalId:Number;
                    var count:Number = 0
                    var maxCount:Number = ProHolder.ProNum;
                    var duration:Number = 70;
                    var VarStart = -3
                    var VarEnd = 8

                    function executeCallback():Void {
                    _global.ProStatus = "Out"
                    CurProd = eval("MenButton" + count)
                    var ProHolderTween1:Object = new Tween(CurProd, "_y", Regular.easeOut,VarStart, VarEnd, 0.3, true );
                    var ProHolderTween2:Object = new Tween(CurProd, "_alpha", Regular.easeOut, 0, 100, 0.3, true );
                    VarStart = VarStart + 13
                    VarEnd = VarEnd + 13
                    if(count >= maxCount) {
                    intervalId = setInterval(this, "executeCallback", duration);