Trigger class

Hey! Yes, I am alive!

Well, today I am going to show you a class that I use a lot. It is a simple one and its utility is also pretty simple, but it is very useful. The Trigger class!
The name is kind of suggestive, a class that executes a function with some delay. You can set how many times you want to repeat the function and pass many arguments you want in a simple way. It also has the possibility to cancel the execution of a function that was set to trigger.

The class has 2 public static methods:
call (delay:Number, fn:Function, repeat:int = 1, ...args)
cancel (fn:Function)

Below I show you how to use the call method:
Trigger.call(2, trace, 1, "param1", "param2", "param3");
Trigger.call(3, test);

Now, how to cancel the execution of a function:
Trigger.cancel(trace);

You can download the class here
If you have any problem, please report it to me.

Oh, and thanks to Eduardo that helped me with this one.

See ya!

Leave a Reply