EventTrigger

EventTrigger

attach and trigger event handlers.

Constructor

new EventTrigger()

Source:
Implements:
Example
const et = new Scene.EventTrigger();
const scene = new Scene();

scene.on("call", e => {
	console.log(e.param);
});
et.on("call", e => {
	console.log(e.param);
});
scene.trigger("call", {param: 1});
et.trigger("call", {param: 1});

Methods

off(nameopt, callbackopt) → {EventTrigger}

Source:
Dettach an event handler function for one or more events to target
Name Type Description
name? string event's name
callback? CallbackType function to execute when the event is triggered.
Example
const callback = function() {
	console.log("animate");
};
target.on("animate", callback);

target.off("animate", callback);
target.off("animate");
Returns:
An Instance itself.
Type
EventTrigger

on(name, callbackopt) → {EventTrigger}

Source:
Attach an event handler function for one or more events to target
Name Type Description
name string | EventParamterType event's name
callback? CallbackType | CallbackType[] function to execute when the event is triggered.
Example
target.on("animate", function() {
	console.log("animate");
});

target.trigger("animate");
Returns:
An Instance itself.
Type
EventTrigger

trigger(name, ...data) → {EventTrigger}

Source:
execute event handler
Name Type Description
name string event's name
...data any[] event handler's additional parameter
Example
target.on("animate", function(a1, a2) {
	console.log("animate", a1, a2);
});

target.trigger("animate", [1, 2]); // log => "animate", 1, 2
Returns:
An Instance itself.
Type
EventTrigger