Function Limiter Example

Tagged:  

The FunctionLimiter class is similar to a callLater function, except you can place it within a function and use it to prevent that function from being called too frequently.

This is good for drawing and invalidating, limiting rapid user input, or any time you want to limit the frequency something occurs.

The example below will call the method 'update' when the button was pressed, but limited to once per second.

Code:

function update():void {
	var allowPass:Boolean = FunctionLimiter.limit(update, 1000, arguments);
	if (!allowPass) return;
}

You can also use the frames method:

function update():void {
	var allowPass:Boolean = FunctionLimiter.limitFrames(update, 12, arguments);
	if (!allowPass) return;
}

Darn it all...
Make sure javascript is enabled and you have an up-to-date version of flash.

Get Adobe Flash player

AttachmentSize
functionLimiterExample.zip11.18 KB
functionLimiterSrc.zip13.1 KB


Post new comment

CAPTCHA
Are you human?
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.