Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do i call a Function from another Function ?

New Here ,
Jul 03, 2013 Jul 03, 2013

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 ?

TOPICS
ActionScript
866
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 03, 2013 Jul 03, 2013

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

}

Translate
Community Expert ,
Jul 03, 2013 Jul 03, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 03, 2013 Jul 03, 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();

};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2013 Jul 03, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 03, 2013 Jul 03, 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...  

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2013 Jul 03, 2013

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 03, 2013 Jul 03, 2013
LATEST

oh you are right!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines