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;
}

This site requires the Flash player to display correctly. Go to http://www.adobe.com/go/getflash/ to download this plugin.

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