Copy link to clipboard
Copied
When i press a button, i want a series of functions to execute one after another (they contain tweens, but its irrelevant), each of them waiting for the previous to be completed. I want to put the series of functions inside one function, so i can call just this function to execute all the others. The animations are working fine, but i dont know how call Functions from within another function. Also it would be necessary each function to wait until the previous has completed, to execute. Here is a clear example of what i need to do:
boton.onPress = animate ;
Function animate () {
animation1 (onComplete: animation2);
animation2 (onComplete: animation3);
animation3 ;
}
Function animation1 () { Tween 1};
Function animation2 () { Tween 2};
Function animation3 () { Tween 3};
any suggestions ?
1 Correct answer
that really doesn't make sense unless you are tweening or doing something asynchronous (like loading a file).
Function b():Void{
C();
D(); // C() has completed execution when this line executes
}
Copy link to clipboard
Copied
you can use setTimeout to do that but because it only makes sense for tweens, you should use a 3rd party tweening class (eg, tweenlite) that makes it easy to chain sequential tweens.
Copy link to clipboard
Copied
I'd do something like this:
boton.onPress = animation1 ;
Function animation1 () {
var Tween1 = new Tween();
Tween1.onComplete = animation2;
};
Function animation2 () {
var Tween2 = new Tween();
Tween2.onComplete = animation3;
};
Function animation3 () {
var Tween3 = new Tween();
};
Copy link to clipboard
Copied
be careful with that. you may find those onComplete's won't execute because the tween instances are local to functions.
Copy link to clipboard
Copied
I guess i will use tweenlite to tell each animation to run one after another. I will tell you after if it worked. However, let's forget about animations for a while. How do i call from inside function A, an external function B? Considering function B has a number of functions inside, how do i tell each of them to wait for the previous to start ? I cant be that hard.
Function A () {
call Function B
}
Function B () {
run Function C
when Function C is over run Function D
and so on...
}
Copy link to clipboard
Copied
that really doesn't make sense unless you are tweening or doing something asynchronous (like loading a file).
Function b():Void{
C();
D(); // C() has completed execution when this line executes
}
Copy link to clipboard
Copied
oh you are right!

