EventDispatcher
Type class
Universal Event Dispatcher.
More info: Events
Sources
This information about EventDispatcher is provided for reference only and is not available through exported packages and thus should not be imported or used on its own.
Inheritance
EventDispatcher does not extend any other symbol.
EventDispatcher is extended by SpriteEventDispatcher.
Properties
EventDispatcher does not have any properties.
Methods
constructor()Returns
EventDispatcherConstructor
disable()Returns
voidDisable dispatching of events until re-enabled by
enable().disableType(type:Key,
amount:number)Returns
voidStops dispatching events of
type, untilenableType()is called or, ifamountis set, for that many dispatches.dispatch(type:Key,
event:T[""])Returns
voidCalls the listeners of
typeright away; debounced listeners are called after their delay.eventmust includetypeandtarget.dispose()Returns
voidDisposes the dispatcher and all its listeners.
enable()Returns
voidEnable dispatching of events if they were previously disabled by
disable().enableType(type:Key)Returns
voidEnable dispatching particular event, if it was disabled before by
disableType().has(type:Key,
callback?:undefined| (this:C, event:T[""]) =>void,
context?:C)Returns
booleanChecks if there's already a listener with specific parameters. Listeners added with
once()are not counted.hasListeners()Returns
booleanChecks if the dispatcher has any listeners.
hasListenersByType(type:Key)Returns
booleanChecks if the dispatcher has listeners for
type, counting the ones added withonAll().isDisposed()Returns
booleanReturns
trueif the dispatcher has been disposed.isEnabled(type:Key)Returns
booleanChecks if an event of
typewould reach a listener: events are enabled, the type is not disabled, and it has listeners.off(type:Key,
callback?:undefined| (this:C, event:T[""]) =>void,
context?:C)Returns
voidRemoves listeners added with
on()oronDebounced()that matchtype,callbackandcontext. Withoutcallback, removes all of them fortypeandcontext. Listeners added withonce()are not removed.on(type:Key,
callback: (this:C|undefined, event:T[""]) =>void,
context?:C,
shouldClone:boolean)Returns
IDisposerCreates an event listener to be invoked on a specific event type.
button.events.on("click", (ev) => { console.log("Button clicked"); }, this);button.events.on("click", function(ev) { console.log("Button clicked"); }, this);The above logs every click on the button. To remove the listener, call
dispose()on the returned object, or useoff().onAll(callback: (this:C, event:T[""]) =>void,
context?:C,
shouldClone:boolean)Returns
IDisposerCreates an event listener to be invoked on any event.
once(type:Key,
callback: (this:C|undefined, event:T[""]) =>void,
context?:C,
shouldClone:boolean)Returns
IDisposerCreates an event listener that is invoked only the first time the event happens, and is then disposed.
button.events.once("click", (ev) => { console.log("Button clicked"); }, this);button.events.once("click", function(ev) { console.log("Button clicked"); }, this);The above logs the first click on the button only.
off()does not remove such a listener: calldispose()on the returned object instead.onDebounced(type:Key,
callback: (this:C|undefined, event:T[""]) =>void,
debounceDelay:number,
context?:C,
shouldClone:boolean)Returns
IDisposerSince 5.14.0Creates a debounced event listener to be invoked on a specific event type.
button.events.onDebounced("click", (ev) => { console.log("Button clicked"); }, 500, this);button.events.onDebounced("click", function(ev) { console.log("Button clicked"); }, 500, this);The above logs once, 500 ms after the last of a series of clicks. Each new event restarts the delay, and
callbackgets the last one.More info: Events: debounced events
removeType(type:Key)Returns
voidRemoves all listeners of a particular event type.
Events
EventDispatcher does not have any events.