all groups > flash actionscript > august 2005 >
You're in the

flash actionscript

group:

Exiting a function



Exiting a function kasnani
8/19/2005 7:28:14 PM
flash actionscript: My actionscript is structured with a series of functions calling each other.
The problem is that I'd like the last function to execute its statements, and
then just stop. I don't want it returning to the previous functions, or for my
code to branch out anywhere else. But my program isn't working correctly, and
by using trace statements, it seems like even without any "return" statements,
the last function still goes back and calls the functions above it.

How do I get my code to just stop executing and sit there and do nothing more?
I don't quite want to go on to the next frame, because that depends on whether
the user clicks a button or not. And I don't want to use the last resort of a
never-ending loop, because the last thing I want is for my program to crash.
I've already tried "break;" (although that shouldn't work anyway since I have
just "if" statements in all my functions, no "for" or "while" loops).
Re: Exiting a function digital_monkey
8/19/2005 8:02:36 PM
The only way that your last function can be calling other functions is if you
have told it to. I'm not sure what you mean when you say your functions are
calling each other. Can you elaborate (maybe with examples) ?
Re: Exiting a function kasnani
8/19/2005 8:05:51 PM
Hi digital_monkey,

What I meant was that I have a statement like: single_func(card_name); in my
first line of code.
So the function single_func is called. The last line in single_func is:
other_func(num);
So the other_func is called. And then other_func has a bunch of statements,
but I don't want it to do anything once those have been executed. However,
judging by the trace statements I added at regular intervals in single_func and
other_func, the code keeps going back to single_func for some reason...
Re: Exiting a function Dave Mennenoh
8/19/2005 8:26:50 PM
I think you might be misunderstanding how functions work. Functions execute
in a single thread so that if function a calls function b - function b will
execute and finish, then return to function a for it to finish. This is just
how it works.

For instance:

function test_a(){
test_b();
trace("in test_a");
}

function test_b(){
trace("in test_b");
}

When you run this, by calling test_a() you will see:

in test_b
in test_a

and then nothing. Function b does not call a - Flash simply returns to the
point it left off, when it was told to branch out and call function b.

HTH

--
Dave -
www.blurredistinction.com/director
www.macromedia.com/go/team

Re: Exiting a function Have A Banana
8/19/2005 9:22:51 PM
Hello,

As monkey pointed out, the only way for functions to call eachother is for you
to write it that way. The best chance for anyone else to figure out why your
script is acting this way is to show what you wrote. Also, do you have code
somewhere else that could be calling your functions? Are you certain they are
calling eachother?
Re: Exiting a function digital_monkey
8/20/2005 9:34:57 PM
That doesn't seem to be the problem. kasnani said that calling other_func() was
the last line of code of single_func(), so there shouldn't be anything more for
single_func to do once other_func has finished.

Can you give us an example of some of the code you have written? Where are you
putting the trace statements? Is the "branching out" causing problems in your
movie?


AddThis Social Bookmark Button