Wiki

Clone wiki

dsair / ThrottleManager

HOWTO: ThrottleManager: Throttling the fps when the app isn't in use

Introduction

A proponent of good app design is only using the minimum necessary power. With this in mind, the ThrottleManager, lowers the fps of the app down to 5 when it's not in use or not active (5 should be enough to keep streaming audio or sockets open). When the app is active again, it brings the fps back up. The ThrottleManager is active by default.

Details

Check out the TestThrottle.as file for the full details.

As with all examples, you need to init the framework before doing anything:

#!actionscript

DSAir.init( this ); // "this" is your Document class

Activating/deactivating the ThrottleManager

By default, the ThrottleManager is active, but if you want to turn it off, you can by using the active property:

#!actionscript

ThrottleManager.instance.active = false;

Getting/setting the fps

The current fps of the app can be retrieved by calling the framerate property:

#!actionscript

ThrottleManager.instance.framerate = 30;

By default, the fps is reset to normal when the app is active, but you can use this so control it programatically.

Getting/setting the active/inactive fps

The active fps is set when the app starts and by default it's the current stage frame rate. The inactive fps is set to 5. You can change either of these by going through the relevant properties:

#!actionscript

ThrottleManager.instance.activeFPS = 30;
ThrottleManager.instance.inactiveFPS = 30;

Finding out if the app is active

You can either call:

#!actionscript

ThrottleManager.instance.isAppActive;

or supply a callback to the app active change listener:

#!actionscript

ThrottleManager.instance.onAppActiveChange = this._onChange;
private function _onChange():void
{
    trace( "The app's activity changed, are we active: " + ThrottleManager.instance.isAppActive );
}

Updated