home *** CD-ROM | disk | FTP | other *** search
- package com.gskinner.utils
- {
- import flash.desktop.NativeApplication;
- import flash.events.Event;
- import flash.system.Capabilities;
-
- public class FramerateThrottler
- {
- protected static var _backgroundFramerate:Number;
-
- protected static var _activeFramerate:Number;
-
- protected static var mac:Boolean;
-
- public static var onlyThrottleOnMac:Boolean = false;
-
- protected static var _active:Boolean = false;
-
- protected static var _enabled:Boolean = true;
-
- public function FramerateThrottler()
- {
- super();
- }
-
- public static function get enabled() : Boolean
- {
- return _enabled;
- }
-
- protected static function throttleFramerate() : void
- {
- if(onlyThrottleOnMac && !mac)
- {
- return;
- }
- var _loc1_:NativeApplication = NativeApplication.nativeApplication;
- if(_loc1_.openedWindows.length > 0)
- {
- _activeFramerate = _loc1_.openedWindows[0].stage.frameRate;
- _loc1_.openedWindows[0].stage.frameRate = _backgroundFramerate;
- }
- }
-
- public static function get active() : Boolean
- {
- return _active;
- }
-
- public static function set enabled(param1:Boolean) : void
- {
- if(param1 == _enabled)
- {
- return;
- }
- _enabled = param1;
- if(!_active && !_enabled)
- {
- restoreFramerate();
- }
- else if(!_active && _enabled)
- {
- throttleFramerate();
- }
- }
-
- public static function initialize(param1:Number = 1, param2:Number = NaN) : void
- {
- var _loc3_:NativeApplication = NativeApplication.nativeApplication;
- if(!isNaN(param2) && param2 > 0)
- {
- _activeFramerate = param2;
- }
- else if(_loc3_.openedWindows.length > 0)
- {
- _activeFramerate = _loc3_.openedWindows[0].stage.frameRate;
- }
- else
- {
- _activeFramerate = 20;
- }
- _backgroundFramerate = param1;
- mac = Capabilities.version.split(" ")[0].toUpperCase() == "MAC";
- _loc3_.addEventListener(Event.DEACTIVATE,handleDeactivate);
- }
-
- protected static function handleActivate(param1:Event) : void
- {
- _active = true;
- if(_enabled)
- {
- restoreFramerate();
- }
- var _loc2_:NativeApplication = NativeApplication.nativeApplication;
- _loc2_.removeEventListener(Event.ACTIVATE,handleActivate);
- _loc2_.addEventListener(Event.DEACTIVATE,handleDeactivate);
- }
-
- protected static function handleDeactivate(param1:Event) : void
- {
- _active = false;
- if(_enabled)
- {
- throttleFramerate();
- }
- var _loc2_:NativeApplication = NativeApplication.nativeApplication;
- _loc2_.removeEventListener(Event.DEACTIVATE,handleDeactivate);
- _loc2_.addEventListener(Event.ACTIVATE,handleActivate);
- }
-
- protected static function restoreFramerate() : void
- {
- if(onlyThrottleOnMac && !mac)
- {
- return;
- }
- var _loc1_:NativeApplication = NativeApplication.nativeApplication;
- if(_loc1_.openedWindows.length > 0)
- {
- _loc1_.openedWindows[0].stage.frameRate = _activeFramerate;
- }
- }
- }
- }
-
-