Packagecom.threerings.util
Classpublic class EventHandlerManager

A class for keeping track of event listeners and freeing them all at a given time. This is useful for keeping track of your ENTER_FRAME listeners, and releasing them all on UNLOAD to make sure your game/furni/avatar fully unloads at the proper time.



Protected Properties
 PropertyDefined by
  _errorHandler : Function
EventHandlerManager
  _listeners : Map
EventHandlerManager
Public Methods
 MethodDefined by
  
EventHandlerManager(globalErrorHandler:Function = null)
Create a EventHandlerManager, optionally specifying a "globalErrorHandler" with the following signature:
        function (error :Error) :void;
     
NOTE: a global error handler will soon be built-in to Flash player 10.1.
EventHandlerManager
  
callWhenTrue(callback:Function, callNow:Boolean, dispatcher:IEventDispatcher, event:String, useCapture:Boolean = false, priority:int = 0):void
Will either call a given function now, or defer it based on the boolean parameter.
EventHandlerManager
  
Free all handlers that have been added via this registerListener() and have not been freed already via unregisterListener()
EventHandlerManager
  
freeAllOn(dispatcher:IEventDispatcher):void
Free all event listeners on the specified dispatcher.
EventHandlerManager
  
registerListener(dispatcher:IEventDispatcher, event:String, listener:Function, useCapture:Boolean = false, priority:int = 0):void
Adds the specified listener to the specified dispatcher for the specified event.
EventHandlerManager
  
registerListenerUntil(triggerDispatcher:IEventDispatcher, triggerEvent:String, dispatcher:IEventDispatcher, event:String, listener:Function):void
Will register a listener on a dispatcher for an event until the trigger event has been dispatched on the trigger dispatcher.
EventHandlerManager
  
registerOneShotCallback(dispatcher:IEventDispatcher, event:String, callback:Function, useCapture:Boolean = false, priority:int = 0):void
Registers a zero-arg callback function that should be called once when the event fires.
EventHandlerManager
  
registerUnload(dispatcher:IEventDispatcher):void
Registers the freeAllHandlers() method to be called upon Event.UNLOAD on the supplied event dispatcher.
EventHandlerManager
  
unregisterListener(dispatcher:IEventDispatcher, event:String, listener:Function, useCapture:Boolean = false):void
Removes the specified listener from the specified dispatcher for the specified event.
EventHandlerManager
Property detail
_errorHandlerproperty
protected var _errorHandler:Function
_listenersproperty 
protected var _listeners:Map
Constructor detail
EventHandlerManager()constructor
public function EventHandlerManager(globalErrorHandler:Function = null)

Create a EventHandlerManager, optionally specifying a "globalErrorHandler" with the following signature:

        function (error :Error) :void;
     
NOTE: a global error handler will soon be built-in to Flash player 10.1.

Parameters
globalErrorHandler:Function (default = null)
Method detail
callWhenTrue()method
public function callWhenTrue(callback:Function, callNow:Boolean, dispatcher:IEventDispatcher, event:String, useCapture:Boolean = false, priority:int = 0):void

Will either call a given function now, or defer it based on the boolean parameter. If the parameter is false, the function will be registered as a one-shot callback on the dispatcher

Parameters
callback:Function
 
callNow:Boolean
 
dispatcher:IEventDispatcher
 
event:String
 
useCapture:Boolean (default = false)
 
priority:int (default = 0)
freeAllHandlers()method 
public function freeAllHandlers():void

Free all handlers that have been added via this registerListener() and have not been freed already via unregisterListener()

freeAllOn()method 
public function freeAllOn(dispatcher:IEventDispatcher):void

Free all event listeners on the specified dispatcher.

Parameters
dispatcher:IEventDispatcher
registerListener()method 
public function registerListener(dispatcher:IEventDispatcher, event:String, listener:Function, useCapture:Boolean = false, priority:int = 0):void

Adds the specified listener to the specified dispatcher for the specified event.

Parameters
dispatcher:IEventDispatcher
 
event:String
 
listener:Function
 
useCapture:Boolean (default = false)
 
priority:int (default = 0)
registerListenerUntil()method 
public function registerListenerUntil(triggerDispatcher:IEventDispatcher, triggerEvent:String, dispatcher:IEventDispatcher, event:String, listener:Function):void

Will register a listener on a dispatcher for an event until the trigger event has been dispatched on the trigger dispatcher. Useful for attaching listeners until an object has been REMOVED_FROM_STAGE or UNLOADed. All associated event listeners use the default useCapture and priority settings.

Parameters
triggerDispatcher:IEventDispatcher
 
triggerEvent:String
 
dispatcher:IEventDispatcher
 
event:String
 
listener:Function
registerOneShotCallback()method 
public function registerOneShotCallback(dispatcher:IEventDispatcher, event:String, callback:Function, useCapture:Boolean = false, priority:int = 0):void

Registers a zero-arg callback function that should be called once when the event fires.

Parameters
dispatcher:IEventDispatcher
 
event:String
 
callback:Function
 
useCapture:Boolean (default = false)
 
priority:int (default = 0)
registerUnload()method 
public function registerUnload(dispatcher:IEventDispatcher):void

Registers the freeAllHandlers() method to be called upon Event.UNLOAD on the supplied event dispatcher.

Parameters
dispatcher:IEventDispatcher
unregisterListener()method 
public function unregisterListener(dispatcher:IEventDispatcher, event:String, listener:Function, useCapture:Boolean = false):void

Removes the specified listener from the specified dispatcher for the specified event.

Parameters
dispatcher:IEventDispatcher
 
event:String
 
listener:Function
 
useCapture:Boolean (default = false)