GlobalTimer Class
by admin on May.14, 2009, under Tutorials
We use the GlobalTimer Class in all our projects. The GlobalTimer Class makes the creation of timers and the registration of functions/methods with the timer very easy. We’ll show you here some key features.
import GlobalTimer;
var my_timer:GlobalTimer = new GlobalTimer();
my_timer.register(my_function);
function my_function():void{
trace("hello");
}
As soon as you register a function with the GlobalTimer, the GlobalTimer starts (or not if you pass false as argument) with default values (10 milliseconds). You can of course pass other values at instantiation time or by accessing the timer regular properties (Timer class). Unregister the function and the timer stops:
my_timer.unregister(my_function);
You can register as many function as you want:
my_timer.register(my_function);
my_timer.register(my_function2);
This will cause the GlobalTimer to run the two functions. By default, passing the same function twice is prevented:
my_timer.register(my_function);
my_timer.register(my_function);//no results
Unregistering a function will not stop the timer if other functions are still registered. You can of course stop the timer anytime using normal Timer properties and methods (Timer class). There’s many other useful methods that you can discover on your own. Enjoy and leave us a comment.
Aswebcreations.com team.
June 18th, 2010 on 4:43 am
the functions that you register should not expect parameters. The shakeRectangles function expects one here: shakeRectangles (e:Event). So this is your problem.
June 15th, 2010 on 3:41 pm
Hello,
I have a strange error :
ArgumentError: Error #1063: Argument count mismatch on GestureRecognitionCoca/shakeRectangles(). Expected 1, got 0.
at GlobalTimer/handle_timer()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
I use:
private var my_timer:GlobalTimer = new GlobalTimer(10, 100, true);
my_timer.register(shakeRectangles);
public function shakeRectangles (e:Event):void {
amount (from -4 to 4)
bottleMc.rotation += Math.random() * 8 - 4;
bottleMc.x += Math.random() * 8 - 4;
bottleMc.y += Math.random() * 8 - 4;
}
Any idea ?
Thanks