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.

Static variables

@:value("touchBegin")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:

PropertyValue
altKeytrue if the Alt key is active (Windows or Linux).
bubblestrue
cancelablefalse; there is no default behavior to cancel.
commandKeytrue on the Mac if the Command key is active; false if it is inactive. Always false on Windows.
controlKeytrue if the Ctrl or Control key is active; false if it is inactive.
ctrlKeytrue 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.
currentTargetThe object that is actively processing the Event object with an event listener.
eventPhaseThe current phase in the event flow.
isRelatedObjectInaccessibletrue if the relatedObject property is set to null because of security sandbox rules.
localXThe horizontal coordinate at which the event occurred relative to the containing sprite.
localYThe vertical coordinate at which the event occurred relative to the containing sprite.
pressureA 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.
relatedObjectA reference to a display list object related to the event.
shiftKeytrue if the Shift key is active; false if it is inactive.
sizeXWidth of the contact area.
sizeYHeight of the contact area.
stageXThe horizontal coordinate at which the event occurred in global stage coordinates.
stageYThe vertical coordinate at which the event occurred in global stage coordinates.
targetThe 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.
touchPointIDA unique identification number (as an int) assigned to the touch point.

@:value("touchEnd")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:

PropertyValue
altKeytrue if the Alt key is active (Windows or Linux).
bubblestrue
cancelablefalse; there is no default behavior to cancel.
commandKeytrue on the Mac if the Command key is active; false if it is inactive. Always false on Windows.
controlKeytrue if the Ctrl or Control key is active; false if it is inactive.
ctrlKeytrue 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.
currentTargetThe object that is actively processing the Event object with an event listener.
eventPhaseThe current phase in the event flow.
isRelatedObjectInaccessibletrue if the relatedObject property is set to null because of security sandbox rules.
localXThe horizontal coordinate at which the event occurred relative to the containing sprite.
localYThe vertical coordinate at which the event occurred relative to the containing sprite.
pressureA 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.
relatedObjectA reference to a display list object related to the event.
shiftKeytrue if the Shift key is active; false if it is inactive.
sizeXWidth of the contact area.
sizeYHeight of the contact area.
stageXThe horizontal coordinate at which the event occurred in global stage coordinates.
stageYThe vertical coordinate at which the event occurred in global stage coordinates.
targetThe 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.
touchPointIDA unique identification number (as an int) assigned to the touch point.

@:value("touchMove")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:

PropertyValue
altKeytrue if the Alt key is active (Windows or Linux).
bubblestrue
cancelablefalse; there is no default behavior to cancel.
commandKeytrue on the Mac if the Command key is active; false if it is inactive. Always false on Windows.
controlKeytrue if the Ctrl or Control key is active; false if it is inactive.
ctrlKeytrue 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.
currentTargetThe object that is actively processing the Event object with an event listener.
eventPhaseThe current phase in the event flow.
isRelatedObjectInaccessibletrue if the relatedObject property is set to null because of security sandbox rules.
localXThe horizontal coordinate at which the event occurred relative to the containing sprite.
localYThe vertical coordinate at which the event occurred relative to the containing sprite.
pressureA 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.
relatedObjectA reference to a display list object related to the event.
shiftKeytrue if the Shift key is active; false if it is inactive.
sizeXWidth of the contact area.
sizeYHeight of the contact area.
stageXThe horizontal coordinate at which the event occurred in global stage coordinates.
stageYThe vertical coordinate at which the event occurred in global stage coordinates.
targetThe 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.
touchPointIDA unique identification number (as an int) assigned to the touch point.

@:value("touchOut")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:

PropertyValue
altKeytrue if the Alt key is active (Windows or Linux).
bubblestrue
cancelablefalse; there is no default behavior to cancel.
commandKeytrue on the Mac if the Command key is active; false if it is inactive. Always false on Windows.
controlKeytrue if the Ctrl or Control key is active; false if it is inactive.
ctrlKeytrue 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.
currentTargetThe object that is actively processing the Event object with an event listener.
eventPhaseThe current phase in the event flow.
isRelatedObjectInaccessibletrue if the relatedObject property is set to null because of security sandbox rules.
localXThe horizontal coordinate at which the event occurred relative to the containing sprite.
localYThe vertical coordinate at which the event occurred relative to the containing sprite.
pressureA 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.
relatedObjectA reference to a display list object related to the event.
shiftKeytrue if the Shift key is active; false if it is inactive.
sizeXWidth of the contact area.
sizeYHeight of the contact area.
stageXThe horizontal coordinate at which the event occurred in global stage coordinates.
stageYThe vertical coordinate at which the event occurred in global stage coordinates.
targetThe 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.
touchPointIDA unique identification number (as an int) assigned to the touch point.

@:value("touchOver")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:

PropertyValue
altKeytrue if the Alt key is active (Windows or Linux).
bubblestrue
cancelablefalse; there is no default behavior to cancel.
commandKeytrue on the Mac if the Command key is active; false if it is inactive. Always false on Windows.
controlKeytrue if the Ctrl or Control key is active; false if it is inactive.
ctrlKeytrue 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.
currentTargetThe object that is actively processing the Event object with an event listener.
eventPhaseThe current phase in the event flow.
isRelatedObjectInaccessibletrue if the relatedObject property is set to null because of security sandbox rules.
localXThe horizontal coordinate at which the event occurred relative to the containing sprite.
localYThe vertical coordinate at which the event occurred relative to the containing sprite.
pressureA 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.
relatedObjectA reference to a display list object related to the event.
shiftKeytrue if the Shift key is active; false if it is inactive.
sizeXWidth of the contact area.
sizeYHeight of the contact area.
stageXThe horizontal coordinate at which the event occurred in global stage coordinates.
stageYThe vertical coordinate at which the event occurred in global stage coordinates.
targetThe 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.
touchPointIDA unique identification number (as an int) assigned to the touch point.

@:value("touchRollOut")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:

PropertyValue
altKeytrue if the Alt key is active (Windows or Linux).
bubblestrue
cancelablefalse; there is no default behavior to cancel.
commandKeytrue on the Mac if the Command key is active; false if it is inactive. Always false on Windows.
controlKeytrue if the Ctrl or Control key is active; false if it is inactive.
ctrlKeytrue 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.
currentTargetThe object that is actively processing the Event object with an event listener.
eventPhaseThe current phase in the event flow.
isRelatedObjectInaccessibletrue if the relatedObject property is set to null because of security sandbox rules.
localXThe horizontal coordinate at which the event occurred relative to the containing sprite.
localYThe vertical coordinate at which the event occurred relative to the containing sprite.
pressureA 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.
relatedObjectA reference to a display list object related to the event.
shiftKeytrue if the Shift key is active; false if it is inactive.
sizeXWidth of the contact area.
sizeYHeight of the contact area.
stageXThe horizontal coordinate at which the event occurred in global stage coordinates.
stageYThe vertical coordinate at which the event occurred in global stage coordinates.
targetThe 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.
touchPointIDA unique identification number (as an int) assigned to the touch point.

@:value("touchRollOver")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:

PropertyValue
altKeytrue if the Alt key is active (Windows or Linux).
bubblestrue
cancelablefalse; there is no default behavior to cancel.
commandKeytrue on the Mac if the Command key is active; false if it is inactive. Always false on Windows.
controlKeytrue if the Ctrl or Control key is active; false if it is inactive.
ctrlKeytrue 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.
currentTargetThe object that is actively processing the Event object with an event listener.
eventPhaseThe current phase in the event flow.
isRelatedObjectInaccessibletrue if the relatedObject property is set to null because of security sandbox rules.
localXThe horizontal coordinate at which the event occurred relative to the containing sprite.
localYThe vertical coordinate at which the event occurred relative to the containing sprite.
pressureA 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.
relatedObjectA reference to a display list object related to the event.
shiftKeytrue if the Shift key is active; false if it is inactive.
sizeXWidth of the contact area.
sizeYHeight of the contact area.
stageXThe horizontal coordinate at which the event occurred in global stage coordinates.
stageYThe vertical coordinate at which the event occurred in global stage coordinates.
targetThe 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.
touchPointIDA unique identification number (as an int) assigned to the touch point.

@:value("touchTap")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:

PropertyValue
altKeytrue if the Alt key is active (Windows or Linux).
bubblestrue
cancelablefalse; there is no default behavior to cancel.
commandKeytrue on the Mac if the Command key is active; false if it is inactive. Always false on Windows.
controlKeytrue if the Ctrl or Control key is active; false if it is inactive.
ctrlKeytrue 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.
currentTargetThe object that is actively processing the Event object with an event listener.
eventPhaseThe current phase in the event flow.
isRelatedObjectInaccessibletrue if the relatedObject property is set to null because of security sandbox rules.
localXThe horizontal coordinate at which the event occurred relative to the containing sprite.
localYThe vertical coordinate at which the event occurred relative to the containing sprite.
pressureA 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.
relatedObjectA reference to a display list object related to the event.
shiftKeytrue if the Shift key is active; false if it is inactive.
sizeXWidth of the contact area.
sizeYHeight of the contact area.
stageXThe horizontal coordinate at which the event occurred in global stage coordinates.
stageYThe vertical coordinate at which the event occurred in global stage coordinates.
targetThe 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.
touchPointIDA unique identification number (as an int) assigned to the touch point.

Constructor

@:value({ isTouchPointCanceled : false, samples : null, touchIntent : null, timestamp : 0, controlKey : false, commandKey : false, shiftKey : false, altKey : false, ctrlKey : false, relatedObject : null, pressure : 0, sizeY : 0, sizeX : 0, localY : 0, localX : 0, isPrimaryTouchPoint : false, touchPointID : 0, cancelable : false, bubbles : true })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: TouchEvent.TOUCH_BEGIN, TouchEvent.TOUCH_END, TouchEvent.TOUCH_MOVE, TouchEvent.TOUCH_OUT, TouchEvent.TOUCH_OVER, TouchEvent.TOUCH_ROLL_OUT, TouchEvent.TOUCH_ROLL_OVER, and TouchEvent.TOUCH_TAP.

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 touchOut event occurs, relatedObject represents the display list object to which the pointing device now points.

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.

isPrimaryTouchPoint:Bool

Indicates whether the first point of contact is mapped to mouse events.

localX:Float

The horizontal coordinate at which the event occurred relative to the containing sprite.

localY:Float

The vertical 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.

shiftKey:Bool

Indicates whether the Shift key is active(true) or inactive (false).

sizeX:Float

Width of the contact area. Only supported on Android(C++ target), in the range of 0-1.

sizeY:Float

Height of the contact area. Only supported on Android(C++ target), in the range of 0-1.

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.

touchPointID:Int

A unique identification number(as an int) assigned to the touch point.

Methods

updateAfterEvent():Void

Instructs OpenFL to render after processing of this event completes, if the display list has been modified.

Inherited Variables

Defined by Event

read onlybubbles:Bool

Indicates whether an event is a bubbling event. If the event can bubble, this value is true; otherwise it is false.

When an event occurs, it moves through the three phases of the event flow: the capture phase, which flows from the top of the display list hierarchy to the node just before the target node; the target phase, which comprises the target node; and the bubbling phase, which flows from the node subsequent to the target node back up the display list hierarchy.

Some events, such as the activate and unload events, do not have a bubbling phase. The bubbles property has a value of false for events that do not have a bubbling phase.

read onlycancelable:Bool

Indicates whether the behavior associated with the event can be prevented. If the behavior can be canceled, this value is true; otherwise it is false.

read onlycurrentTarget:Object

The object that is actively processing the Event object with an event listener. For example, if a user clicks an OK button, the current target could be the node containing that button or one of its ancestors that has registered an event listener for that event.

read onlyeventPhase:EventPhase

The current phase in the event flow. This property can contain the following numeric values:

read onlytarget:Object

The event target. This property contains the target node. For example, if a user clicks an OK button, the target node is the display list node containing that button.

read onlytype:String

The type of event. The type is case-sensitive.

Inherited Methods

Defined by Event

@:value({ p5 : null, p4 : null, p3 : null, p2 : null, p1 : null })formatToString(className:String, ?p1:String, ?p2:String, ?p3:String, ?p4:String, ?p5:String):String

A utility function for implementing the toString() method in custom ActionScript 3.0 Event classes. Overriding the toString() method is recommended, but not required.

class PingEvent extends Event {
	var URL:String;

	public function new() {
		super();
	}

	public override function toString():String {
		return formatToString("PingEvent", "type", "bubbles", "cancelable", "eventPhase", "URL");
	}
}

Parameters:

className

The name of your custom Event class. In the previous example, the className parameter is PingEvent.

Returns:

The name of your custom Event class and the String value of your ...arguments parameter.

isDefaultPrevented():Bool

Checks whether the preventDefault() method has been called on the event. If the preventDefault() method has been called, returns true; otherwise, returns false.

Returns:

If preventDefault() has been called, returns true; otherwise, returns false.

preventDefault():Void

Cancels an event's default behavior if that behavior can be canceled. Many events have associated behaviors that are carried out by default. For example, if a user types a character into a text field, the default behavior is that the character is displayed in the text field. Because the TextEvent.TEXT_INPUT event's default behavior can be canceled, you can use the preventDefault() method to prevent the character from appearing. An example of a behavior that is not cancelable is the default behavior associated with the Event.REMOVED event, which is generated whenever Flash Player is about to remove a display object from the display list. The default behavior (removing the element) cannot be canceled, so the preventDefault() method has no effect on this default behavior. You can use the Event.cancelable property to check whether you can prevent the default behavior associated with a particular event. If the value of Event.cancelable is true, then preventDefault() can be used to cancel the event; otherwise, preventDefault() has no effect.

stopImmediatePropagation():Void

Prevents processing of any event listeners in the current node and any subsequent nodes in the event flow. This method takes effect immediately, and it affects event listeners in the current node. In contrast, the stopPropagation() method doesn't take effect until all the event listeners in the current node finish processing.

Note: This method does not cancel the behavior associated with this event; see preventDefault() for that functionality.

stopPropagation():Void

Prevents processing of any event listeners in nodes subsequent to the current node in the event flow. This method does not affect any event listeners in the current node(currentTarget). In contrast, the stopImmediatePropagation() method prevents processing of event listeners in both the current node and subsequent nodes. Additional calls to this method have no effect. This method can be called in any phase of the event flow.

Note: This method does not cancel the behavior associated with this event; see preventDefault() for that functionality.