Skip to main content
Known Participant
October 21, 2009
Answered

How do I reset multiple timers?

  • October 21, 2009
  • 1 reply
  • 1467 views

I am fairly new to Action Script and I am having a rough time finding the solution to making my timers

loop after the last timer has completed. Can someone please help?

Here is the code:

import fl.transitions.Tween;
import fl.transitions.easing.*;


var learnDone:Timer=new Timer(3000);
learnDone.addEventListener(TimerEvent.TIMER, timerDone1);
learnDone.start();

var learnDoneMore:Timer=new Timer(6000);
learnDoneMore.addEventListener(TimerEvent.TIMER, timerDone2);
learnDoneMore.start();

var learnDoneMost:Timer=new Timer(9000);
learnDoneMost.addEventListener(TimerEvent.TIMER, timerDone3);
learnDoneMost.start();


var myFirstFade:Tween=new Tween(learn_mc,"alpha",Strong.easeOut,0,1,7,true);//this fades in the first object

function timerDone1(e:TimerEvent):void {
var myFirstFade:Tween=new Tween(learn_mc,"alpha",Strong.easeOut,1,0,7,true);//this fades out the first object
var mySecondFade:Tween=new Tween(intentionally_mc,"alpha",Strong.easeOut,0,1,7,true);//this fades in the second object
learnDone.stop();
}

function timerDone2(e:TimerEvent):void {
var mySecondFade:Tween=new Tween(intentionally_mc,"alpha",Strong.easeOut,1,0,7,true);//this fades out the second object
var myThirdFade:Tween=new Tween(succeed_mc,"alpha",Strong.easeOut,0,1,7,true);//this fades in the third object
learnDoneMore.stop();

}

function timerDone3(e:TimerEvent):void {
var myThirdFade:Tween=new Tween(succeed_mc,"alpha",Strong.easeOut,1,0,7,true);//this fades out the third object
learnDoneMost.stop();

}

function timerComplete(e:TimerEvent):void{
    stopLearnDone3();
    nextFrame();
}

This topic has been closed for replies.
Correct answer Ned Murphy

I tried that and it works until the first word fades in. The last word fades in again even though

I told it to stop. It's as though the timers are getting confused.

Thanks again for your help.


I don't know if the timers are getting confused or just the presentation due to the duration of the tweens.  Below is the code I was describing, but I have shortened the duration of the tweens so that they don't start to conflict with the timing of the timers.

import fl.transitions.Tween;
import fl.transitions.easing.*;

learn_mc.alpha = 0;
intentionally_mc.alpha = 0;
succeed_mc.alpha = 0;

var learnDone:Timer=new Timer(3000);
learnDone.addEventListener(TimerEvent.TIMER, timerDone1);

var learnDoneMore:Timer=new Timer(3000);
learnDoneMore.addEventListener(TimerEvent.TIMER, timerDone2);

var learnDoneMost:Timer=new Timer(3000);
learnDoneMost.addEventListener(TimerEvent.TIMER, timerDone3);


var myFirstFade:Tween=new Tween(learn_mc,"alpha",Strong.easeOut,0,1,3,true);//this fades in the first object
learnDone.start();

function timerDone1(e:TimerEvent):void {
var myFirstFade:Tween=new Tween(learn_mc,"alpha",Strong.easeOut,1,0,3,true);//this fades out the first object
var mySecondFade:Tween=new Tween(intentionally_mc,"alpha",Strong.easeOut,0,1,3,true);//this fades in the second object
learnDone.stop();
learnDoneMore.start();
}

function timerDone2(e:TimerEvent):void {
var mySecondFade:Tween=new Tween(intentionally_mc,"alpha",Strong.easeOut,1,0,3,true);//this fades out the second object
var myThirdFade:Tween=new Tween(succeed_mc,"alpha",Strong.easeOut,0,1,3,true);//this fades in the third object
learnDoneMore.stop();
learnDoneMost.start();
}

function timerDone3(e:TimerEvent):void {
var myThirdFade:Tween=new Tween(succeed_mc,"alpha",Strong.easeOut,1,0,3,true);//this fades out the third object
var myFirstFade:Tween=new Tween(learn_mc,"alpha",Strong.easeOut,0,1,3,true);//this fades in the first object
learnDoneMost.stop();
learnDone.start();
}

1 reply

Ned Murphy
Legend
October 22, 2009

When you tell the timer to stop() you have essentially reset it, you can just as easily tell it to start() again.

You might find it easier to manage if you only have on timer running at a time.  Have your first timer's handler tell the second tiimer to start, have the second timer's handler tell the third to start... and to loop things, you probably need a fourth timer.

There are other ways to approach this where only one timer would be needed, but for now stick with what you have and try to reason things thru.

Known Participant
October 22, 2009

Thanks Ned!

So, let me explain this a little better.

The word learn tweens in, stops and then intentionally fades in next to it.

At that point learn fades out and succeed tweens in.

Once that occurs, everything fades out, but stops.

I am having trouble finding the code to make the animation start again from the beginning.

Any ideas? Thank you!

Ned Murphy
Legend
October 22, 2009

Yep, as I said, have your timers work sequentially... set each for 3 seconds.  The first timer's event handler function will stop the first timer and tell the second timer to start, the second timer's event handler will stop the second timer and tell the third timer to start, the third timer's event handler will stop the third timer and tell a fourth timer to start things all over again--the fourth brings in the first word again, fading out the last, and telling the first timer to start again.