Event Properties
Events have properties that describe the event.
In the event handler code for an event, you know what event has occurred. For example, if you are handling a TapDown
event, you know that the user has tapped down on the node. But what if you need to know where the user tapped down?
The Tap and Pointer events all contain these additional properties:
point
- the point on the node where the event occurred.buttons
- the buttons that were pressed when the event occurred.type
- the type of event that occurred, as a string, such asTapDown
orPointerMove
.target
- the node on which the event occurred.1handled
- a boolean value that indicates whether the event has been handled. If the event has been handled, then the event will not be passed to any other nodes. This is useful for preventing the event from being handled by multiple nodes.
The event's point
property is the most useful Tap and Pointer event property. The others are for more advanced scenarios.
The below example prints where on the button the user tapped down. To access the event properties, you provide a variable to represent the event in the event handler code. The variable name can be anything you want, but by convention it is common to use the name e
, ev
, or event
.
- A more advanced example: use a single event handler, called
buttonEventHandler()
for different buttons and events. Examine the event'stype
property to know which event occurred and thetarget
property to know which button had the event.
Footnotes
-
target
is similar to the concept ofsender
in C# event handling and the object returned byEventObject.getSource()
in Java. ↩