Reputation: 153
Here is the code I am using:
import flash.utils.Timer;
import flash.events.TimerEvent;
//Pausing the timeline
function wait(){
stop();
var timer:Timer=new Timer(2000,1);
timer.addEventListener(TimerEvent.TIMER,waitdone);
timer.start();
}
function waitdone(e:TimerEvent){
e.currentTarget.removeEventListener(TimerEvent.TIMER,waitdone);
play();
}
When I call the following function, it pauses for 2 seconds, easy. What I can't figure out to do is call wait();
and add another second onto it to get 3 seconds rather than two.
Is there an easy way of doing this?
Upvotes: 0
Views: 3755
Reputation: 1023
You mean like this?
function wait(numberOfSeconds:int){
stop();
var timer:Timer=new Timer(numberOfSeconds * 1000);
timer.addEventListener(TimerEvent.TIMER,waitdone);
timer.start();
}
Then you call it using wait(2) or wait(3) depending on how many seconds you want.
Upvotes: 2
Reputation: 11590
What about something like this:
import flash.utils.Timer;
import flash.events.TimerEvent;
var currentDelay:Number = 2000;
//Pausing the timeline
function wait(){
stop();
var timer:Timer=new Timer(currentDelay,1);
timer.addEventListener(TimerEvent.TIMER,waitdone);
timer.start();
}
function waitdone(e:TimerEvent){
e.stop();
if(currentDelay > 10000){ //stop it after lets say when delay reaches over 11 seconds
e.currentTarget.removeEventListener(TimerEvent.TIMER,waitdone);
play();
} else {
currentDelay += 1000;
e.delay = currentDelay;
e.reset();
e.start();
}
}
The general idea is you keep a currentDelay variable outside of your functions to keep track of the current delay you are at. You can increment this variable from whatever other function that has scope to it.
Upvotes: 1