Say I have this:
function f1():void {
if (!paused) {
// animate something
// start timer and when it's done execute f2()
} else {
??
}
}
function f2(te:TimerEvent):void {
if (!paused) {
// animate something
// start timer and when it's done execute f3()
} else {
??
}
}
function f3(me:TimerEvent):void {
if (!paused) {
// animate something then execute f4()
} else {
??
}
}
function f4():void {
if (!paused) {
// animate something
} else {
??
}
}
This series of functions happen serially as can be seen. I have a pause button that, when clicked, sets “paused” to true. This interrupts the flow of the animations, which is what I want to happen.
My problem is, how do I restart the animations when I unpause? I assume this would happen where the ??'s are.
I guess I could set up an Enter Frame listener that constantly checks the value of paused, but I would prefer a more, well, elegant solution.
Is there a way for me to define a variable:
var currentFunction:Function = new Function();
…that I can set, in the ‘else’, to the function it’s in, like this?
function f4():void {
if (!paused) {
// animate something
} else {
// somehow set currentFunction to f4();
}
}
And then, in the function that sets paused to true or false, execute that function, like this:
function setPause(me:MouseEvent) { // click a pause button
if (!paused) {
paused = true;
} else {
paused = false;
currentFunction();
}
}
Then too, for the functions passed a TimerEvent object, would I define a second function like this?
var currentFunctionTimer:Function = new Function(te:TimerEvent);
I was thinking that instead of this I could dispatch a new TimerEvent but there are multiple functions that get passed a TimerEvent object so it doesn’t seem like that would work.
Thanks!