…and controls to pause and play the time line.
I’ve been using this script quite a bit, and I think it’s time to jog it down somewhere. A few things to keep in mind when using this script:
- Try not to use this script on the main/root time line. If you have movie clips within the main timeline, when the timer is up, it speeds through the entire time line to the every end. Stop(); won’t do anything.
- This script works well inside a movie clip, also works for movie clips within a movie clip. But try to minimize it to only one clip
- The controls (Pause, Play) buttons work best in the main / root time line, doesn’t work too well if there are clips within a clip
Just insert the following 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 addition if you want to have Pause / Play buttons, insert the following 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);
}
}
