PXEventDispatcher Class Reference
| Inherits from | NSObject |
| Conforms to | PXEventDispatcher |
| Declared in | PXEventDispatcher.h PXEventDispatcher.m |
Overview
The base class for all classes that dispatch events. The event dispatcher allows individual methods to be associated with any event.
Event types are represented as NSString objects and methods are wrapped in PXEventListener objects, while information about events is passed along in PXEvent objects.
The PXEventDispatcher is the base class for all display objects.
the PXEventDispatcher class maybe subclassed by any user class in order to provide event dispatching behavior for that class. If a user class is unable to subclass PXEventDispatcher because it is already subclassing a different class, it may implement the PXEventDispatcher protocol.
In order to implement the methods of the protocol, a private PXEventDispatcher ivar should be created, to which all of the protocol method calls should be forwarded.See the PXEventDispatcher protocol for more information.
Tasks
-
dispatchEventsAssign
propertyYESif this event dispatcher should dispatch events. -
– initWithTarget:Makes a new event disptacher with the given target.
-
– addEventListenerOfType:listener:Adds an event listener.
-
– addEventListenerOfType:listener:useCapture:priority:Adds an event listener.
-
– removeEventListenerOfType:listener:Removes an event listener.
-
– removeEventListenerOfType:listener:useCapture:Removes an event listener.
-
– removeAllEventListenersRemoves all of the event listeners.
-
– dispatchEvent:Invokes the event on all listeners of the same type as
event. -
– hasEventListenerOfType:Returns
YESif this event dispatcher has a listener of the type. -
– willTriggerEventOfType:This method returns
YESif an event listener is triggered during any phase of the event flow when an event of the specified type is dispatched to this EventDispatcher object or any of its descendants.
Instance Methods
addEventListenerOfType:listener:
Adds an event listener.
- (BOOL)addEventListenerOfType:(NSString *)type listener:(PXEventListener *)listenerParameters
- type
The type
- listener
The listener
Discussion
Example:
In this example the method onTouch: is assigned as a
listener to the stage’s touchDown event.
[self.stage addEventListenerForType:PXTouchEvent_TouchDown listener:PXListener(onTouchDown:)];
//...
- (void) onTouchDown:(PXTouchEvent *)event
{
// handle event
}
Declared In
PXEventDispatcher.maddEventListenerOfType:listener:useCapture:priority:
Adds an event listener.
- (BOOL)addEventListenerOfType:(NSString *)type listener:(PXEventListener *)listener useCapture:(BOOL)useCapture priority:(int)priorityParameters
- type
The type
- listener
The listener
- priority
The priority
- capture
If it should use capture
Discussion
Example:
In this example the method onTouch: is assigned as a
listener to the stage’s touchDown event.
[self.stage addEventListenerForType:PXTouchEvent_TouchDown listener:PXListener(onTouchDown:) useCapture:NO priority:0];
//...
- (void) onTouchDown:(PXTouchEvent *)event
{
// handle event
}
Declared In
PXEventDispatcher.mdispatchEvent:
Invokes the event on all listeners of the same type as event.
- (BOOL)dispatchEvent:(PXEvent *)eventParameters
- event
The event
Return Value
YES if the event completed.
Declared In
PXEventDispatcher.mhasEventListenerOfType:
Returns YES if this event dispatcher has a listener of the
type.
- (BOOL)hasEventListenerOfType:(NSString *)typeParameters
- type
The type.
Return Value
Returns YES if this event dispatcher has a listener of the
type.
Declared In
PXEventDispatcher.minitWithTarget:
Makes a new event disptacher with the given target.
- (id)initWithTarget:(id<PXEventDispatcher>)_targetParameters
- target
The target.
Declared In
PXEventDispatcher.mremoveAllEventListeners
Removes all of the event listeners.
- (void)removeAllEventListenersDeclared In
PXEventDispatcher.mremoveEventListenerOfType:listener:
Removes an event listener.
- (BOOL)removeEventListenerOfType:(NSString *)type listener:(PXEventListener *)listenerParameters
- type
The type
- listener
The listener
Declared In
PXEventDispatcher.mremoveEventListenerOfType:listener:useCapture:
Removes an event listener.
- (BOOL)removeEventListenerOfType:(NSString *)type listener:(PXEventListener *)listener useCapture:(BOOL)useCaptureParameters
- type
The type
- listener
The listener
- capture
If it should use capture
Declared In
PXEventDispatcher.mwillTriggerEventOfType:
This method returns YES if an event listener is triggered
during any phase of the event flow when an event of the specified type is
dispatched to this EventDispatcher object or any of its descendants.
- (BOOL)willTriggerEventOfType:(NSString *)typeParameters
- type
The type
Return Value
This method returns YES if an event listener is triggered
during any phase of the event flow when an event of the specified type
is dispatched to this EventDispatcher object or any of its descendants.
Discussion
Essentially, checks the entire flow path of the event, were it to dispatch right now, and sees if any node along the path has an event listener. This really only applies to display object sinceonly they have event flow…
Declared In
PXEventDispatcher.m