When it comes to functions that are only meant to run for a short time and then stop, is there a way for that same function to create its own timer and then use it to time the function's run? This probably isn't a thing, but what about creating a new "instance" of a function when you call it?
For the longest time, I've always had to create an int timer in the class variables and then iterate that timer from the function. When the timer reaches a certain amount, I'll usually do something to end the function and reset the timer. Like so:
//class variables
var counter:int = 0;
var condition:Boolean = false;
//function tied to the ENTER_FRAME
if(condition == true)[
timedFunction();
}
//and the timed function
function timedFunction(){
counter++;
if(counter >= 30){
condition = false;
counter = 0;
}
}
Normally, I don't mind keeping the timer independent of the function, but I'm trying to turn such functions into static functions that I can keep in that Utility class I talked about before. The function I'm working on now is one that affects the color of an object, but I want to be able to reuse it through the whole project without having to paste the function and variable into each class.
I know I can paste the variable into the Utility class and use it that way, but that means that each object using this function will be on the exact same time. if I wanted something to occur at a specific timing moment, it wouldn't happen equally on each object.
So, I'm not sure. All I can think of is creating a new timer or somehow using a new instance of a function each time it's called. If there's another way, I'm all ears.