Skip to main content
Inspiring
February 12, 2009
Question

Deleting/Stopping Functions from running

  • February 12, 2009
  • 3 replies
  • 475 views
Hi,

In AS3, how do you delete or stop a function from running? For example
in Frame 3, I have a function called createAnimation(); running, and
when the user goes back to Frame 1, I want createAnimation(); to stop
running, what is the best way of stopping or deleting the function?
Thanks for any help.

CT
This topic has been closed for replies.

3 replies

kglad
Community Expert
Community Expert
February 12, 2009
removing it isn't going to help you. if you don't want it to run, don't call it.

if you did remove it and still called it, you would generate a runtime error.
Inspiring
February 12, 2009
Kglad,

Thanks for the reply. I am looking for a code structure for example:
delete functionName(); ( or in my case in my earlier example it would be
delete createAnimation(); .... And was wondering if there is such a code
that just eliminates the function if we want to stop it from executing or
running.

It is so easy to create and call functions, but my brains are drawing a
blank on creating the code to help void the function.

CT


On 2/12/09 1:49 AM, in article gn0kb6$knd$1@forums.macromedia.com, "kglad"
<webforumsuser@macromedia.com> wrote:

> under normal circumstances the code in a function executes from the first
> throught the last statement so rapidly you cannot stop it.
>
> on the other hand, if you're repeatedly calling a function, that you can stop
> (assuming you don't have an endless loop).
>

February 12, 2009
You can set an object, in this case you function to null, this removes it and frees up its associated memory. But this only works on dynamically created functions, so only ones you define at runtime.

Here's a quick hacked together example of creating a function at runtime, put three buttons on the timeline called "createBtn" "showBtn" and "deleteBtn" and then put this code on the timeline.

Bewarned through once the function is deleted flash will throw up an error that it cannot find the function to call. To suppress this just wrap the call to the function in a try-catch block
kglad
Community Expert
Community Expert
February 12, 2009
under normal circumstances the code in a function executes from the first throught the last statement so rapidly you cannot stop it.

on the other hand, if you're repeatedly calling a function, that you can stop (assuming you don't have an endless loop).