Phaser. Signal

new Signal()

A Signal is an event dispatch mechansim than supports broadcasting to multiple listeners.

Event listeners are uniquely identified by the listener/callback function and the context.

Source - core/Signal.js, line 16

Members

active :boolean

Is the Signal active? Only active signal will broadcast dispatched events.

Setting this property during a dispatch will only affect the next dispatch. To stop the propagation of a signal from a listener use halt.

Default Value:
  • true
Source - core/Signal.js, line 57

memorize :boolean

Memorize the previously dispatched event?

If an event has been memorized it is automatically dispatched when a new listener is added with add or addOnce. Use forget to clear any currently memorized event.

Source - core/Signal.js, line 41

Methods

add(listener, listenerContext, priority) → {Phaser.SignalBinding}

Add an event listener.

Parameters:
Name Type Argument Description
listener function

The function to call when this Signal is dispatched.

listenerContext object <optional>

The context under which the listener will be executed (i.e. the object that should represent the this variable).

priority number <optional>

The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added (default = 0)

Returns:

An Object representing the binding between the Signal and listener.

Source - core/Signal.js, line 189

addOnce(listener, listenerContext, priority) → {Phaser.SignalBinding}

Add a one-time listener - the listener is automatically removed after the first execution.

If there is as memorized event then it will be dispatched and the listener will be removed immediately.

Parameters:
Name Type Argument Description
listener function

The function to call when this Signal is dispatched.

listenerContext object <optional>

The context under which the listener will be executed (i.e. the object that should represent the this variable).

priority number <optional>

The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added (default = 0)

Returns:

An Object representing the binding between the Signal and listener.

Source - core/Signal.js, line 206

dispatch(params)

Dispatch / broadcast the event to all listeners.

To create an instance-bound dispatch for this Signal, use boundDispatch.

Parameters:
Name Type Argument Description
params any <optional>

Parameters that should be passed to each handler.

Source - core/Signal.js, line 316

dispose()

Dispose the signal - no more events can be dispatched.

This removes all event listeners and clears references to external objects. Calling methods on a disposed objects results in undefined behavior.

Source - core/Signal.js, line 372

forget()

Forget the currently memorized event, if any.

Source - core/Signal.js, line 358

getNumListeners() → {integer}

Gets the total number of listeners attached to this Signal.

Returns:
integer -

Number of listeners attached to the Signal.

Source - core/Signal.js, line 290

halt()

Stop propagation of the event, blocking the dispatch to next listener on the queue.

This should be called only during event dispatch as calling it before/after dispatch won't affect other broadcast. See active to enable/disable the signal entirely.

Source - core/Signal.js, line 302

has(listener, context) → {boolean}

Check if a specific listener is attached.

Parameters:
Name Type Argument Description
listener function

Signal handler function.

context object <optional>

Context on which listener will be executed (object that should represent the this variable inside listener function).

Returns:
boolean -

If Signal has the specified listener.

Source - core/Signal.js, line 175

remove(listener, context) → {function}

Remove a single event listener.

Parameters:
Name Type Argument Default Description
listener function

Handler function that should be removed.

context object <optional>
null

Execution context (since you can add the same handler multiple times if executing in a different context).

Returns:
function -

Listener handler function.

Source - core/Signal.js, line 226

removeAll(context)

Remove all event listeners.

Parameters:
Name Type Argument Default Description
context object <optional>
null

If specified only listeners for the given context will be removed.

Source - core/Signal.js, line 250

toString() → {string}

A string representation of the object.

Returns:
string -

String representation of the object.

Source - core/Signal.js, line 392
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Wed Dec 03 2014 10:31:00 GMT-0000 (GMT) using the DocStrap template.