Name Mon Lu

Love jQuery/CSS

Blog about Webdev

Twitter supawaza

RSS Twitter Flickr

What I am up to:


…and con­trols to pause and play the time line.

thumb

I’ve been using this script quite a bit, and I think it’s time to jog it down some­where. A few things to keep in mind when using this script:

  1. Try not to use this script on the main/root time line. If you have movie clips within the main time­line, when the timer is up, it speeds through the entire time line to the every end. Stop(); won’t do anything.
  2. This script works well inside a movie clip, also works for movie clips within a movie clip. But try to min­i­mize it to only one clip
  3. The con­trols (Pause, Play) but­tons work best in the main / root time line, doesn’t work too well if there are clips within a clip

Just insert the fol­low­ing inside a movie clip’s time line where you want it to pauses for a few moments:

	 stop();

    var startTime:Number = getTimer();
    var pausedTime = 0;
    //countTo = number of seconds.
    var countTo:Number = 10;
    var ref:MovieClip = this;

    this.onEnterFrame = function():Void {
        if (!paused) {
            var elapsedTime:Number = getTimer()-ref.startTime-pausedTime;
            var count:Number = Math.ceil(countTo-(elapsedTime*0.001));
            if(count<1){
                this.gotoAndPlay(nextFrame());
            }
        }
    }

In addi­tion if you want to have Pause / Play but­tons, insert the fol­low­ing codes after the above codes:

	_root.puz1.onRelease = function() {
       if (!paused) {
          pauseTime = getTimer();
          paused=true;
          _root.puz1.gotoAndStop(2);
       }
    }
    _root.play1.onRelease = function() {
       if (paused) {
          pausedTime += getTimer() - pauseTime;
          paused=false;
          _root.puz1.gotoAndStop(1);
       }
    }

timeline

This entry was posted on Wednesday, August 12th, 2009 at 10:29 AM and is filed under Others, Web Dev. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.