...

/

Custom Events

Custom Events

Learn more about custom events and their properties in this lesson.

Events help us communicate with different entities by sending signals that other pieces of code can pick up and respond to. There can be requirements for which we need to achieve a customized behavior against a specific type of event. To accomplish this, A-frame offers custom events.

Emitting events

Using the emit(eventName, eventDetail, bubbles) function, we can emit from any entity element. For example, we can use the emit() function to define a changescale named event and pass target scale values to the event listener using the eventDetail argument:

entityEl.emit('changescale', { x: 2.0, y: 2.0, z: 2.0 }, false);

In the code above, the data is passed as a dictionary containing the scale values along the three axes. When we want to access the x value passed into this event, we can access it using the event.detail.x property. ...