STOP an onClipEvent(enterFrame)

Hi, there all…

Someone toll me that if I use “lots” of onClipEvent(enterFrame) events
my movie it may get just a lot slower… so…

is there a script or way to stop the enterFrame when its events have been processed?

I was thinking to use:

onClipEvent(enterFrame){
// do Stuff calculation from 1 to 100
calculation = calculation +=1;
if(calculation <= 100){
// do stuff until calculation => 100;
}else{
break;
}

is it ok, or is there a smarter way?

THANKS

well something like what you have, but your calculation = calculation += 1; should look like:


calculation++;

++ is just another way of doing it (and more popular) - doesnt make += 1 wrong, just a little unconventional since += 1 is so much harder to type than ++ :wink:

there’s no real way to stop an onClipEvent(enterFrame), as I think you’ve seen (or discovered). Using an if condition like that is the best way to prevent the actions within from going on. You can further improve its effectiveness, however, as with how you have it now, the onEnterFrame is still adding 1 to calculation even when its no longer being used. A simple “flag” variable can be used instead - something that will be changed within the if statement that would further prevent it from running again:

onClipEvent(load){
   // set up variables
   calculation = 0;
   doCalculation = true; // our flag
}
onClipEvent(enterFrame){
   if(doCalculation){ // if true
      // do stuff
      calculation++; // add 1 to calculation
      if (calculation > 100) doCalculation = false; // if condition false, code within ignored
   }
   // else is not needed since there's nothing else to do anyway
}

so doCalculation here is changed to false based on whether or not the calculation counter reaches 100 or not. This is quick because its contained within the if block and a boolean (true or false) flag variable is used to make it easily managable and readable for that matter.

yes, “calculation += 1” would work too, but “calculation = calculation += 1” results in NaN :wink:

That’s cool Sen, I’ll have to keep that kind of thing in mind next time I have to do something like this. You wouldn’t by chance happen to know how much it improves the efficiency by would you?