7 Replies Latest reply on Aug 6, 2007 1:38 PM by Greg Dove

    complete a function and  then move on...

      Ok, this is probably a simple question:
      I have three functions (FunctionOne, FunctionTwo and FunctionThree). It is very important that these functions fire in order and that one function doesn't fire until the previous function has completed. I assume the answer to this problem involves adding a listener to each function but I can't seem to make it work.
      Thanks
        • 1. Re: complete a function and  then move on...
          Damon Edwards Level 3
          You could use an Interval or onEnterFrame to check for variables, and as each function executes, it sets a variable to lets say 1, then in an if statement, it will go on to the next function.. just set the variables to 0 before any functions execute.
          • 2. Re: complete a function and  then move on...
            Level 7
            How about this? I can't think of a scenario where it would not work.

            FunctionOne();
            FunctionTwo();
            FunctionThree();


            Seems to me this was asked and answered last week.


            1 person found this helpful
            • 3. Re: complete a function and  then move on...
              Level 7
              It really depends on what you're doing in each of these functions. At
              its very simplest, you can call the next function from the last line of
              the current function. Or, you may need to set some boolean variables
              that are tripped by something in one function as dzedward suggests.

              Maybe if you give us a scenario that describes what you're up to,
              someone can give you a suggestion that will work for you.
              --
              Rob

              ___________
              Rob Dillon
              Adobe Community Expert
              http://www.ddg-designs.com
              412.243.9119
              1 person found this helpful
              • 4. Re: complete a function and  then move on...
                That is what I'm doing now:

                FunctionOne();
                FunctionTwo();
                FunctionThree();

                It does work, but I was worried that it might not be 100% safe. Does the fact that there is one thread in this case mean that each function completes before the next one starts?
                • 5. Re: complete a function and  then move on...
                  Rothrock Level 5
                  I've never had a problem. Of course your functions can't have any onEnterFrame, setInterval, externally loaded assets, that determine when they are done.
                  1 person found this helpful
                  • 6. Re: complete a function and  then move on...
                    SymTsb Level 2
                    what language are you using - AS2? AS3?
                    • 7. Re: complete a function and  then move on...
                      Greg Dove Level 4
                      Just backing up earlier comments....If the function calls are in order like that and just running as part of a sequence of instructions and not triggered by any event handlers then they should always run in order.... unless you do something intentional like mess around with them (e.g. functionOne reassigns functionTwo to functionThree and vice versa).

                      On a slightly different note... If the code is running in a frame on a timeline then it also doesn't matter whether the functions are defined before or after the function calls within that frame. Its also OK if they were defined in a frame on higher layers in the authoring tool. But the function doesn't exist yet if its defined in a layer lower down. This was not something I knew until just recently when someone else had a question about it and I tried it. I had assumed that the layers - which don't exist in a compiled swf would not make a difference - but it seems they do.