I'm coding a Javascript Web app and I want to send a custom event when a controller button is pressed. That event should have custom parameters: event.index, event.player2, and event.button. However, none of them are defined in the resulting event. This is what I tried so far:
I first declared the event as follows:
var testEvent = new Event('controllerPress', {
index: 0,
player2: false,
button: 12
});
After that didn't work, I looked up some Q&As online (like this), and redeclared the event as such...
var testEvent = new Event('controllerPress', {
detail: {
index: 0,
player2: false,
button: 12
}
});
...but to no avail. I looked again and changed the declaration to use CustomEvent
...
var testEvent = new CustomEvent('controllerPress', {
detail: {
index: 0,
player2: false,
button: 12
}
});
...but testEvent.index
is still undefined. What am I missing?
EDIT: This is not a duplicate of “Create JavaScript custom event” because that asks how to create a custom event at all, but this asks how to add a custom property to that custom event.