Event is a strictly-typed signals and slots implementation, used for core event dispatching.

For example:

var event = new Event<Int->Void> ();
event.add (function (value:Int):Void { trace (value); });
event.dispatch (100);

var event = new Event<Void->Void> ();
event.add (function () { trace ("callback"); });
event.dispatch ();

Constructor

new()

Creates a new Event instance

Variables

read onlycanceled:Bool

Whether the event was canceled during the previous dispatch

dispatch:Dynamic

Dispatches a new event callback to all listeners. The signature for the dispatch method depends upon the type of the Event. For example, an Event of type Int->Int->Void will create a dispatch method that takes two Int arguments, like dispatch (1, 2);

Methods

@:value({ priority : 0, once : false })add(listener:T, once:Bool = false, priority:Int = 0):Void

Adds a new event listener

Parameters:

listener

A callback that matches the signature of the event

once

Whether to receive an event dispatch only once, or each time it is fired

priority

The priority for this listener, a higher priority will be dispatched sooner

cancel():Void

Marks the event as canceled, and stops the current event dispatch

has(listener:T):Bool

Checks whether a callback is a listener to this event

Parameters:

listener

A callback that matches the signature of the event

Returns:

Whether the callback is a listener

remove(listener:T):Void

Removes an event listener

Parameters:

listener

A callback that matches the signature of the event

removeAll():Void

Removes all event listeners