Skip to main content
August 6, 2007
Answered

complete a function and then move on...

  • August 6, 2007
  • 7 replies
  • 329 views
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
This topic has been closed for replies.
Correct answer Greg Dove
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.

7 replies

Greg DoveCorrect answer
Inspiring
August 6, 2007
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.

Inspiring
August 6, 2007
what language are you using - AS2? AS3?
Inspiring
August 6, 2007
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.
August 6, 2007
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?
Inspiring
August 6, 2007
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
Inspiring
August 6, 2007
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.


Damon Edwards
Inspiring
August 6, 2007
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.