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

Properties

dispatchEvents

Assign YES if this event dispatcher should dispatch events.

@property (nonatomic, assign) BOOL dispatchEvents

Discussion

Default: YES

Declared In

PXEventDispatcher.h

Instance Methods

addEventListenerOfType:listener:

Adds an event listener.

- (BOOL)addEventListenerOfType:(NSString *)type listener:(PXEventListener *)listener

Parameters

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.m

addEventListenerOfType:listener:useCapture:priority:

Adds an event listener.

- (BOOL)addEventListenerOfType:(NSString *)type listener:(PXEventListener *)listener useCapture:(BOOL)useCapture priority:(int)priority

Parameters

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.m

dispatchEvent:

Invokes the event on all listeners of the same type as event.

- (BOOL)dispatchEvent:(PXEvent *)event

Parameters

event

The event

Return Value

YES if the event completed.

Declared In

PXEventDispatcher.m

hasEventListenerOfType:

Returns YES if this event dispatcher has a listener of the type.

- (BOOL)hasEventListenerOfType:(NSString *)type

Parameters

type

The type.

Return Value

Returns YES if this event dispatcher has a listener of the type.

Declared In

PXEventDispatcher.m

initWithTarget:

Makes a new event disptacher with the given target.

- (id)initWithTarget:(id<PXEventDispatcher>)_target

Parameters

target

The target.

Declared In

PXEventDispatcher.m

removeAllEventListeners

Removes all of the event listeners.

- (void)removeAllEventListeners

Declared In

PXEventDispatcher.m

removeEventListenerOfType:listener:

Removes an event listener.

- (BOOL)removeEventListenerOfType:(NSString *)type listener:(PXEventListener *)listener

Parameters

type

The type

listener

The listener

Declared In

PXEventDispatcher.m

removeEventListenerOfType:listener:useCapture:

Removes an event listener.

- (BOOL)removeEventListenerOfType:(NSString *)type listener:(PXEventListener *)listener useCapture:(BOOL)useCapture

Parameters

type

The type

listener

The listener

capture

If it should use capture

Declared In

PXEventDispatcher.m

willTriggerEventOfType:

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 *)type

Parameters

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