EventDispatcher - Verge3D User Manual - Soft8Soft
Description: Learn how to use EventDispatcher in your interactive 3D apps made with Verge3D

# EventDispatcher

JavaScript custom events.

## Code Example

`// adding events to a custom object class Car extends EventDispatcher { start() { this.dispatchEvent({ type: 'start', message: 'vroom vroom!' }); } }; // using events with the custom object const car = new Car(); car.addEventListener('start', function(event) { alert(event.message); }); car.start();`

## Constructor

### EventDispatcher()

Creates EventDispatcher object.

## Methods

### # .addEventListener(type : String, listener : Function)

- type — the type of event to listen to.
- listener — the function that gets called when the event is fired.

Adds a listener to an event type.

### # .hasEventListener(type : String, listener : Function) → Boolean

- type — the type of event to listen to.
- listener — the function that gets called when the event is fired.

Checks if listener is added to an event type.

### # .removeEventListener(type : String, listener : Function)

- type — the type of the listener that gets removed.
- listener — the listener function that gets removed.

Removes a listener from an event type.

### # .dispatchEvent(event : Object)

event — the event that gets fired.

Fire an event type.

## Puzzles

There is a set of puzzles that implements similar functionality in a visual manner:

- add event listener
- remove event listener
- dispatch event

## Source

For more info on how to obtain the source code of this module see this page.