The TouchEvent class lets you handle events on devices that detect user contact with the device (such as a finger on a touch screen). When a user interacts with a device such as a mobile phone or tablet with a touch screen, the user typically touches the screen with his or her fingers or a pointing device. You can develop applications that respond to basic touch events(such as a single finger tap) with the TouchEvent class. Create event listeners using the event types defined in this class. For user interaction with multiple points of contact (such as several fingers moving across a touch screen at the same time) use the related GestureEvent, PressAndTapGestureEvent, and TransformGestureEvent classes. And, use the properties and methods of these classes to construct event handlers that respond to the user touching the device.
Use the Multitouch class to determine the current environment's support for touch interaction, and to manage the support of touch interaction if the current environment supports it.
Note: When objects are nested on the display list, touch events
target the deepest possible nested object that is visible in the display
list. This object is called the target node. To have a target node's
ancestor(an object containing the target node in the display list) receive
notification of a touch event, use
EventDispatcher.addEventListener()
on the ancestor node with
the type parameter set to the specific touch event you want to detect.
See also:
Static variables
staticinlineread onlyTOUCH_BEGIN:EventType<TouchEvent> = "touchBegin"
Defines the value of the type
property of a TOUCH_BEGIN
touch
event object.
The dispatched TouchEvent object has the following properties:
Property | Value |
---|---|
altKey | true if the Alt key is active (Windows or Linux). |
bubbles | true |
cancelable | false ; there is no default behavior to cancel. |
commandKey | true on the Mac if the Command key is active; false if it is inactive. Always false on Windows. |
controlKey | true if the Ctrl or Control key is active; false if it is inactive. |
ctrlKey | true on Windows or Linux if the Ctrl key is active. true on Mac if either the Ctrl key or the Command key is active. Otherwise, false . |
currentTarget | The object that is actively processing the Event object with an event listener. |
eventPhase | The current phase in the event flow. |
isRelatedObjectInaccessible | true if the relatedObject property is set to null because of security sandbox rules. |
localX | The horizontal coordinate at which the event occurred relative to the containing sprite. |
localY | The vertical coordinate at which the event occurred relative to the containing sprite. |
pressure | A value between 0.0 and 1.0 indicating force of the contact with the device. If the device does not support detecting the pressure, the value is 1.0 . |
relatedObject | A reference to a display list object related to the event. |
shiftKey | true if the Shift key is active; false if it is inactive. |
sizeX | Width of the contact area. |
sizeY | Height of the contact area. |
stageX | The horizontal coordinate at which the event occurred in global stage coordinates. |
stageY | The vertical coordinate at which the event occurred in global stage coordinates. |
target | The InteractiveObject instance under the touching device. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event. |
touchPointID | A unique identification number (as an int) assigned to the touch point. |
staticinlineread onlyTOUCH_END:EventType<TouchEvent> = "touchEnd"
Defines the value of the type
property of a TOUCH_END
touch event
object.
The dispatched TouchEvent object has the following properties:
Property | Value |
---|---|
altKey | true if the Alt key is active (Windows or Linux). |
bubbles | true |
cancelable | false ; there is no default behavior to cancel. |
commandKey | true on the Mac if the Command key is active; false if it is inactive. Always false on Windows. |
controlKey | true if the Ctrl or Control key is active; false if it is inactive. |
ctrlKey | true on Windows or Linux if the Ctrl key is active. true on Mac if either the Ctrl key or the Command key is active. Otherwise, false . |
currentTarget | The object that is actively processing the Event object with an event listener. |
eventPhase | The current phase in the event flow. |
isRelatedObjectInaccessible | true if the relatedObject property is set to null because of security sandbox rules. |
localX | The horizontal coordinate at which the event occurred relative to the containing sprite. |
localY | The vertical coordinate at which the event occurred relative to the containing sprite. |
pressure | A value between 0.0 and 1.0 indicating force of the contact with the device. If the device does not support detecting the pressure, the value is 1.0 . |
relatedObject | A reference to a display list object related to the event. |
shiftKey | true if the Shift key is active; false if it is inactive. |
sizeX | Width of the contact area. |
sizeY | Height of the contact area. |
stageX | The horizontal coordinate at which the event occurred in global stage coordinates. |
stageY | The vertical coordinate at which the event occurred in global stage coordinates. |
target | The InteractiveObject instance under the touching device. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event. |
touchPointID | A unique identification number (as an int) assigned to the touch point. |
staticinlineread onlyTOUCH_MOVE:EventType<TouchEvent> = "touchMove"
Defines the value of the type
property of a TOUCH_MOVE
touch event
object.
The dispatched TouchEvent object has the following properties:
Property | Value |
---|---|
altKey | true if the Alt key is active (Windows or Linux). |
bubbles | true |
cancelable | false ; there is no default behavior to cancel. |
commandKey | true on the Mac if the Command key is active; false if it is inactive. Always false on Windows. |
controlKey | true if the Ctrl or Control key is active; false if it is inactive. |
ctrlKey | true on Windows or Linux if the Ctrl key is active. true on Mac if either the Ctrl key or the Command key is active. Otherwise, false . |
currentTarget | The object that is actively processing the Event object with an event listener. |
eventPhase | The current phase in the event flow. |
isRelatedObjectInaccessible | true if the relatedObject property is set to null because of security sandbox rules. |
localX | The horizontal coordinate at which the event occurred relative to the containing sprite. |
localY | The vertical coordinate at which the event occurred relative to the containing sprite. |
pressure | A value between 0.0 and 1.0 indicating force of the contact with the device. If the device does not support detecting the pressure, the value is 1.0 . |
relatedObject | A reference to a display list object related to the event. |
shiftKey | true if the Shift key is active; false if it is inactive. |
sizeX | Width of the contact area. |
sizeY | Height of the contact area. |
stageX | The horizontal coordinate at which the event occurred in global stage coordinates. |
stageY | The vertical coordinate at which the event occurred in global stage coordinates. |
target | The InteractiveObject instance under the touching device. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event. |
touchPointID | A unique identification number (as an int) assigned to the touch point. |
staticinlineread onlyTOUCH_OUT:EventType<TouchEvent> = "touchOut"
Defines the value of the type
property of a TOUCH_OUT
touch event
object.
The dispatched TouchEvent object has the following properties:
Property | Value |
---|---|
altKey | true if the Alt key is active (Windows or Linux). |
bubbles | true |
cancelable | false ; there is no default behavior to cancel. |
commandKey | true on the Mac if the Command key is active; false if it is inactive. Always false on Windows. |
controlKey | true if the Ctrl or Control key is active; false if it is inactive. |
ctrlKey | true on Windows or Linux if the Ctrl key is active. true on Mac if either the Ctrl key or the Command key is active. Otherwise, false . |
currentTarget | The object that is actively processing the Event object with an event listener. |
eventPhase | The current phase in the event flow. |
isRelatedObjectInaccessible | true if the relatedObject property is set to null because of security sandbox rules. |
localX | The horizontal coordinate at which the event occurred relative to the containing sprite. |
localY | The vertical coordinate at which the event occurred relative to the containing sprite. |
pressure | A value between 0.0 and 1.0 indicating force of the contact with the device. If the device does not support detecting the pressure, the value is 1.0 . |
relatedObject | A reference to a display list object related to the event. |
shiftKey | true if the Shift key is active; false if it is inactive. |
sizeX | Width of the contact area. |
sizeY | Height of the contact area. |
stageX | The horizontal coordinate at which the event occurred in global stage coordinates. |
stageY | The vertical coordinate at which the event occurred in global stage coordinates. |
target | The InteractiveObject instance under the touching device. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event. |
touchPointID | A unique identification number (as an int) assigned to the touch point. |
staticinlineread onlyTOUCH_OVER:EventType<TouchEvent> = "touchOver"
Defines the value of the type
property of a TOUCH_OVER
touch event
object.
The dispatched TouchEvent object has the following properties:
Property | Value |
---|---|
altKey | true if the Alt key is active (Windows or Linux). |
bubbles | true |
cancelable | false ; there is no default behavior to cancel. |
commandKey | true on the Mac if the Command key is active; false if it is inactive. Always false on Windows. |
controlKey | true if the Ctrl or Control key is active; false if it is inactive. |
ctrlKey | true on Windows or Linux if the Ctrl key is active. true on Mac if either the Ctrl key or the Command key is active. Otherwise, false . |
currentTarget | The object that is actively processing the Event object with an event listener. |
eventPhase | The current phase in the event flow. |
isRelatedObjectInaccessible | true if the relatedObject property is set to null because of security sandbox rules. |
localX | The horizontal coordinate at which the event occurred relative to the containing sprite. |
localY | The vertical coordinate at which the event occurred relative to the containing sprite. |
pressure | A value between 0.0 and 1.0 indicating force of the contact with the device. If the device does not support detecting the pressure, the value is 1.0 . |
relatedObject | A reference to a display list object related to the event. |
shiftKey | true if the Shift key is active; false if it is inactive. |
sizeX | Width of the contact area. |
sizeY | Height of the contact area. |
stageX | The horizontal coordinate at which the event occurred in global stage coordinates. |
stageY | The vertical coordinate at which the event occurred in global stage coordinates. |
target | The InteractiveObject instance under the touching device. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event. |
touchPointID | A unique identification number (as an int) assigned to the touch point. |
staticinlineread onlyTOUCH_ROLL_OUT:EventType<TouchEvent> = "touchRollOut"
Defines the value of the type
property of a TOUCH_ROLL_OUT
touch
event object.
The dispatched TouchEvent object has the following properties:
Property | Value |
---|---|
altKey | true if the Alt key is active (Windows or Linux). |
bubbles | true |
cancelable | false ; there is no default behavior to cancel. |
commandKey | true on the Mac if the Command key is active; false if it is inactive. Always false on Windows. |
controlKey | true if the Ctrl or Control key is active; false if it is inactive. |
ctrlKey | true on Windows or Linux if the Ctrl key is active. true on Mac if either the Ctrl key or the Command key is active. Otherwise, false . |
currentTarget | The object that is actively processing the Event object with an event listener. |
eventPhase | The current phase in the event flow. |
isRelatedObjectInaccessible | true if the relatedObject property is set to null because of security sandbox rules. |
localX | The horizontal coordinate at which the event occurred relative to the containing sprite. |
localY | The vertical coordinate at which the event occurred relative to the containing sprite. |
pressure | A value between 0.0 and 1.0 indicating force of the contact with the device. If the device does not support detecting the pressure, the value is 1.0 . |
relatedObject | A reference to a display list object related to the event. |
shiftKey | true if the Shift key is active; false if it is inactive. |
sizeX | Width of the contact area. |
sizeY | Height of the contact area. |
stageX | The horizontal coordinate at which the event occurred in global stage coordinates. |
stageY | The vertical coordinate at which the event occurred in global stage coordinates. |
target | The InteractiveObject instance under the touching device. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event. |
touchPointID | A unique identification number (as an int) assigned to the touch point. |
staticinlineread onlyTOUCH_ROLL_OVER:EventType<TouchEvent> = "touchRollOver"
Defines the value of the type
property of a TOUCH_ROLL_OVER
touch
event object.
The dispatched TouchEvent object has the following properties:
Property | Value |
---|---|
altKey | true if the Alt key is active (Windows or Linux). |
bubbles | true |
cancelable | false ; there is no default behavior to cancel. |
commandKey | true on the Mac if the Command key is active; false if it is inactive. Always false on Windows. |
controlKey | true if the Ctrl or Control key is active; false if it is inactive. |
ctrlKey | true on Windows or Linux if the Ctrl key is active. true on Mac if either the Ctrl key or the Command key is active. Otherwise, false . |
currentTarget | The object that is actively processing the Event object with an event listener. |
eventPhase | The current phase in the event flow. |
isRelatedObjectInaccessible | true if the relatedObject property is set to null because of security sandbox rules. |
localX | The horizontal coordinate at which the event occurred relative to the containing sprite. |
localY | The vertical coordinate at which the event occurred relative to the containing sprite. |
pressure | A value between 0.0 and 1.0 indicating force of the contact with the device. If the device does not support detecting the pressure, the value is 1.0 . |
relatedObject | A reference to a display list object related to the event. |
shiftKey | true if the Shift key is active; false if it is inactive. |
sizeX | Width of the contact area. |
sizeY | Height of the contact area. |
stageX | The horizontal coordinate at which the event occurred in global stage coordinates. |
stageY | The vertical coordinate at which the event occurred in global stage coordinates. |
target | The InteractiveObject instance under the touching device. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event. |
touchPointID | A unique identification number (as an int) assigned to the touch point. |
staticinlineread onlyTOUCH_TAP:EventType<TouchEvent> = "touchTap"
Defines the value of the type
property of a TOUCH_TAP
touch event
object.
The dispatched TouchEvent object has the following properties:
Property | Value |
---|---|
altKey | true if the Alt key is active (Windows or Linux). |
bubbles | true |
cancelable | false ; there is no default behavior to cancel. |
commandKey | true on the Mac if the Command key is active; false if it is inactive. Always false on Windows. |
controlKey | true if the Ctrl or Control key is active; false if it is inactive. |
ctrlKey | true on Windows or Linux if the Ctrl key is active. true on Mac if either the Ctrl key or the Command key is active. Otherwise, false . |
currentTarget | The object that is actively processing the Event object with an event listener. |
eventPhase | The current phase in the event flow. |
isRelatedObjectInaccessible | true if the relatedObject property is set to null because of security sandbox rules. |
localX | The horizontal coordinate at which the event occurred relative to the containing sprite. |
localY | The vertical coordinate at which the event occurred relative to the containing sprite. |
pressure | A value between 0.0 and 1.0 indicating force of the contact with the device. If the device does not support detecting the pressure, the value is 1.0 . |
relatedObject | A reference to a display list object related to the event. |
shiftKey | true if the Shift key is active; false if it is inactive. |
sizeX | Width of the contact area. |
sizeY | Height of the contact area. |
stageX | The horizontal coordinate at which the event occurred in global stage coordinates. |
stageY | The vertical coordinate at which the event occurred in global stage coordinates. |
target | The InteractiveObject instance under the touching device. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event. |
touchPointID | A unique identification number (as an int) assigned to the touch point. |
Constructor
new(type:String, bubbles:Bool = true, cancelable:Bool = false, touchPointID:Int = 0, isPrimaryTouchPoint:Bool = false, localX:Float = 0, localY:Float = 0, sizeX:Float = 0, sizeY:Float = 0, pressure:Float = 0, ?relatedObject:InteractiveObject, ctrlKey:Bool = false, altKey:Bool = false, shiftKey:Bool = false, commandKey:Bool = false, controlKey:Bool = false, timestamp:Float = 0, ?touchIntent:String, ?samples:ByteArray, isTouchPointCanceled:Bool = false)
Creates an Event object that contains information about touch events. Event objects are passed as parameters to event listeners.
Parameters:
type | The type of the event. Possible values are:
|
---|---|
bubbles | Determines whether the Event object participates in the bubbling phase of the event flow. |
cancelable | Determines whether the Event object can be canceled. |
touchPointID | A unique identification number (as an int) assigned to the touch point. |
isPrimaryTouchPoint | Indicates whether the first point of contact is mapped to mouse events. |
relatedObject | The complementary InteractiveObject instance
that is affected by the event. For example,
when a |
ctrlKey | On Windows or Linux, indicates whether the Ctrl key is activated. On Mac, indicates whether either the Ctrl key or the Command key is activated. |
altKey | Indicates whether the Alt key is activated (Windows or Linux only). |
shiftKey | Indicates whether the Shift key is activated. |
Variables
altKey:Bool
Indicates whether the Alt key is active (true
) or inactive
(false
). Supported for Windows and Linux operating systems
only.
commandKey:Bool
Indicates whether the command key is activated (Mac only).
On a Mac OS, the value of the commandKey
property is the same value as the
ctrlKey
property. This property is always false
on Windows or Linux.
controlKey:Bool
Indicates whether the Control key is activated on Mac and whether the Ctrl key is activated on Windows or Linux.
ctrlKey:Bool
On Windows or Linux, indicates whether the Ctrl key is active
(true
) or inactive (false
). On Macintosh,
indicates whether either the Control key or the Command key is activated.
localX:Float
The horizontal coordinate at which the event occurred relative to the containing sprite.
pressure:Float
A value between 0.0
and 1.0
indicating force of
the contact with the device. If the device does not support detecting the
pressure, the value is 1.0
.
relatedObject:InteractiveObject
A reference to a display list object that is related to the event. For
example, when a touchOut
event occurs,
relatedObject
represents the display list object to which the
pointing device now points. This property applies to the
touchOut
, touchOver
, touchRollOut
,
and touchRollOver
events.
The value of this property can be null
in two
circumstances: if there is no related object, or there is a related
object, but it is in a security sandbox to which you don't have access.
Use the isRelatedObjectInaccessible()
property to determine
which of these reasons applies.
stageX:Float
The horizontal coordinate at which the event occurred in global Stage
coordinates. This property is calculated when the localX
property is set.
stageY:Float
The vertical coordinate at which the event occurred in global Stage
coordinates. This property is calculated when the localY
property is set.
Methods
updateAfterEvent():Void
Instructs OpenFL to render after processing of this event completes, if the display list has been modified.