GODPAPER | All Packages | All Classes | Index | Frames No Frames |
TouchEvent

Package | starling.events
Class | public class TouchEvent
Inheritance | TouchEvent Event Object

A TouchEvent is triggered either by touch or mouse input.

In Starling, both touch events and mouse events are handled through the same class: TouchEvent. To process user input from a touch screen or the mouse, you have to register an event listener for events of the type `TouchEvent.TOUCH`. This is the only event type you need to handle; the long list of mouse event types as they are used in conventional Flash are mapped to so-called "TouchPhases" instead.

The difference between mouse input and touch input is that

- only one mouse cursor can be present at a given moment and
- only the mouse can "hover" over an object without a pressed button.

Which objects receive touch events?

In Starling, any display object receives touch events, as long as the `touchable` property of the object and its parents is enabled. There is no "InteractiveObject" class in Starling.

How to work with individual touches

The event contains a list of all touches that are currently present. Each individual touch is stored in an object of type "Touch". Since you are normally only interested in the touches that occurred on top of certain objects, you can query the event for touches with a specific target:

`var touches:Vector.<Touch> = touchEvent.getTouches(this);`

This will return all touches of "this" or one of its children. When you are not using multitouch, you can also access the touch object directly, like this:

`var touch:Touch = touchEvent.getTouch(this);`

See also

Touch
TouchPhase

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | bubbles : Boolean [read-only] Indicates if event will bubble. | Event
|  | ctrlKey : Boolean [read-only] Indicates if the ctrl key was pressed when the event occurred. | TouchEvent
|  | currentTarget : EventDispatcher [read-only] The object the event is currently bubbling at. | Event
|  | data : Object [read-only] Arbitrary data that is attached to the event. | Event
|  | shiftKey : Boolean [read-only] Indicates if the shift key was pressed when the event occurred. | TouchEvent
|  | target : EventDispatcher [read-only] The object that dispatched the event. | Event
|  | timestamp : Number [read-only] The time the event occurred (in seconds since application launch). | TouchEvent
|  | touches : Vector.<Touch> [read-only] All touches that are currently available. | TouchEvent
|  | type : String [read-only] A string that identifies the event. | Event

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | TouchEvent(type:String, touches:Vector.<Touch>, shiftKey:Boolean = false, ctrlKey:Boolean = false, bubbles:Boolean = true) Creates a new TouchEvent instance. | TouchEvent
|  | getTouch(target:DisplayObject, phase:String = null, id:int = -1):Touch Returns a touch that originated over a certain target. | TouchEvent
|  | getTouches(target:DisplayObject, phase:String = null, result:Vector.<Touch> = null):Vector.<Touch> Returns a list of touches that originated over a certain target. | TouchEvent
|  | interactsWith(target:DisplayObject):Boolean Indicates if a target is currently being touched or hovered over. | TouchEvent
|  | stopImmediatePropagation():void Prevents any other listeners from receiving the event. | Event
|  | stopPropagation():void Prevents listeners at the next bubble stage from receiving the event. | Event
|  | toString():String Returns a description of the event, containing type and bubble information. | Event

Public Constants
Hide Inherited Public Constants
Show Inherited Public Constants

| Constant | Defined By
--- | --- | ---
|  | ADDED : String = added [static] Event type for a display object that is added to a parent. | Event
|  | ADDED_TO_STAGE : String = addedToStage [static] Event type for a display object that is added to the stage | Event
|  | CANCEL : String = cancel [static] An event type to be utilized in custom events. | Event
|  | CHANGE : String = change [static] An event type to be utilized in custom events. | Event
|  | CLOSE : String = close [static] An event type to be utilized in custom events. | Event
|  | COMPLETE : String = complete [static] Event type that may be used whenever something finishes. | Event
|  | CONTEXT3D_CREATE : String = context3DCreate [static] Event type for a (re)created stage3D rendering context. | Event
|  | ENTER_FRAME : String = enterFrame [static] Event type for a display object that is entering a new frame. | Event
|  | FLATTEN : String = flatten [static] Event type for a display object that is being flattened. | Event
|  | OPEN : String = open [static] An event type to be utilized in custom events. | Event
|  | REMOVED : String = removed [static] Event type for a display object that is removed from its parent. | Event
|  | REMOVED_FROM_STAGE : String = removedFromStage [static] Event type for a display object that is removed from the stage. | Event
|  | REMOVE_FROM_JUGGLER : String = removeFromJuggler [static] Event type for an animated object that requests to be removed from the juggler. | Event
|  | RESIZE : String = resize [static] Event type for a resized Flash Player. | Event
|  | ROOT_CREATED : String = rootCreated [static] Event type that indicates that the root DisplayObject has been created. | Event
|  | SCROLL : String = scroll [static] An event type to be utilized in custom events. | Event
|  | SELECT : String = select [static] An event type to be utilized in custom events. | Event
|  | TEXTURES_RESTORED : String = texturesRestored [static] Event type that is dispatched by the AssetManager after a context loss. | Event
|  | TOUCH : String = touch [static] Event type for touch or mouse input. | TouchEvent
|  | TRIGGERED : String = triggered [static] Event type for a triggered button. | Event

Property Detail

ctrlKey | property

`ctrlKey:Boolean` [read-only]

Indicates if the ctrl key was pressed when the event occurred. (Mac OS: Cmd or Ctrl)

Implementation
`public function get ctrlKey():Boolean`

shiftKey | property |

`shiftKey:Boolean` [read-only]

Indicates if the shift key was pressed when the event occurred.

Implementation
`public function get shiftKey():Boolean`

timestamp | property |

`timestamp:Number` [read-only]

The time the event occurred (in seconds since application launch).

Implementation
`public function get timestamp():Number`

touches | property |

`touches:Vector.<Touch>` [read-only]

All touches that are currently available.

Implementation
`public function get touches():Vector.<Touch>`
Constructor Detail

TouchEvent | () | Constructor

`public function TouchEvent(type:String, touches:Vector.<Touch>, shiftKey:Boolean = false, ctrlKey:Boolean = false, bubbles:Boolean = true)`

Creates a new TouchEvent instance.

Parameters

| `type:String`
| `touches:Vector.<Touch>`
| `shiftKey:Boolean` (default = `false`)``
| `ctrlKey:Boolean` (default = `false`)``
| `bubbles:Boolean` (default = `true`)``

Method Detail

getTouch | () | method

`public function getTouch(target:DisplayObject, phase:String = null, id:int = -1):Touch`

Returns a touch that originated over a certain target.

Parameters

| `target:DisplayObject` — The object that was touched; may also be a parent of the actual touch-target.
| `phase:String` (default = `null`)`` — The phase the touch must be in, or null if you don't care.
| `id:int` (default = `-1`)`` — The ID of the requested touch, or -1 if you don't care.

Returns

| `Touch`

getTouches | () | method |

`public function getTouches(target:DisplayObject, phase:String = null, result:Vector.<Touch> = null):Vector.<Touch>`

Returns a list of touches that originated over a certain target. If you pass a 'result' vector, the touches will be added to this vector instead of creating a new object.

Parameters

| `target:DisplayObject`
| `phase:String` (default = `null`)``
| `result:Vector.<Touch>` (default = `null`)``

Returns

| `Vector.<Touch>`

interactsWith | () | method |

`public function interactsWith(target:DisplayObject):Boolean`

Indicates if a target is currently being touched or hovered over.

Parameters

| `target:DisplayObject`

Returns

| `Boolean`

Constant Detail

TOUCH | Constant

`public static const TOUCH:String = touch`

Event type for touch or mouse input.

Thu Jan 16 2014, 01:11 PM +08:00