Skip to main content
Participating Frequently
July 3, 2013
Answered

How do i call a Function from another Function ?

  • July 3, 2013
  • 2 replies
  • 1030 views

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 ?

This topic has been closed for replies.
Correct answer kglad

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...  

}


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

}

2 replies

Participating Frequently
July 3, 2013

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();

};

kglad
Community Expert
Community Expert
July 3, 2013

be careful with that. you may find those onComplete's won't execute because the tween instances are local to functions.

brsastreAuthor
Participating Frequently
July 4, 2013

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...  

}

kglad
Community Expert
Community Expert
July 3, 2013

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.