TouchEvent

public class
loom2d.events.TouchEvent

Description

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:
loom2d.events.Touch
loom2d.events.TouchPhase

API overview

Constructor

TouchEvent ( type: String = , touches: Vector.<Touch> = null , shiftKey: Boolean = false , ctrlKey: Boolean = false , bubbles: Boolean = true )
Creates a new TouchEvent instance

Attributes

Public attributes

ctrlKey: Boolean read-only

Indicates if the ctrl key was pressed when the event occurred

shiftKey: Boolean read-only

Indicates if the shift key was pressed when the event occurred

timestamp: Number read-only

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

touches: Vector.<Touch> read-only

All touches that are currently available

Constants

Constants

TOUCH: String static

Event type for touch or mouse input

Functions

Public functions

getTouch ( target: DisplayObject , phase: String = null ): Touch

Returns a touch that originated over a certain target

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

Returns a list of touches that originated over a certain target

interactsWith ( target: DisplayObject ): Boolean

Indicates if a target is currently being touched or hovered over

resetTouch ( type: String , touches: Vector.<Touch> , shiftKey: Boolean = false , ctrlKey: Boolean = false , bubbles: Boolean = true ): Void

Constructor

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

Creates a new TouchEvent instance.

Attributes

bubbles: Boolean
Inherited from Event

read-only

Indicates if event will bubble.

ctrlKey: Boolean

read-only

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

currentTarget: EventDispatcher
Inherited from Event

read-only

The object the event is currently bubbling at.

data: Object
Inherited from Event

read-only

Arbitrary data that is attached to the event.

shiftKey: Boolean

read-only

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

target: EventDispatcher
Inherited from Event

read-only

The object that dispatched the event.

timestamp: Number

read-only

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

touches: Vector.<Touch>

read-only

All touches that are currently available.

type: String
Inherited from Event

read-only

A string that identifies the event.

Constants

ADDED: String

static

Event type for a display object that is added to a parent.

ADDED_TO_STAGE: String

static

Event type for a display object that is added to the stage

CANCEL: String

static

An event type to be utilized in custom events. Not used by Starling right now.

CHANGE: String

static

An event type to be utilized in custom events. Not used by Starling right now.

CLOSE: String

static

An event type to be utilized in custom events. Not used by Starling right now.

COMPLETE: String

static

Event type that may be used whenever something finishes.

CONTEXT3D_CREATE: String

static

Event type for a (re)created stage3D rendering context.

ENTER_FRAME: String

static

Event type for a display object that is entering a new frame.

FLATTEN: String

static

Event type for a display object that is being flattened.

OPEN: String

static

An event type to be utilized in custom events. Not used by Starling right now.

REMOVED: String

static

Event type for a display object that is removed from its parent.

REMOVED_FROM_STAGE: String

static

Event type for a display object that is removed from the stage.

REMOVE_FROM_JUGGLER: String

static

Event type for an animated object that requests to be removed from the juggler.

RESIZE: String

static

Event type for a resized Flash Player.

ROOT_CREATED: String

static

Event type that indicates that the root DisplayObject has been created.

SCROLL: String

static

An event type to be utilized in custom events. Not used by Starling right now.

SELECT: String

static

An event type to be utilized in custom events. Not used by Starling right now.

TOUCH: String

static

Event type for touch or mouse input.

TRIGGERED: String

static

Event type for a triggered button.

Functions

clone (): Event
Inherited from Event

Clones the event object with the same arguments and returns the duplicate.


Returns

Event The duplicate event object that was cloned.

getFullTypeName (): String
Inherited from Object

native

Gets the fully qualified type name of the Object. The fully qualified type name includes the package of the type.


Returns

String fully qualified type name of the Object.

getTouch ( target: DisplayObject , phase: String = null ): Touch

Returns a touch that originated over a certain target.

Parameters

target: DisplayObject
phase: String = null


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 = null
result: Vector.<Touch> = null


getType (): Type
Inherited from Object

native

Gets the Type that describes the Object.


Returns

Type The Type that describes the object.

getTypeName (): String
Inherited from Object

native

Gets the type name of the Object.


Returns

String type name of the Object.

interactsWith ( target: DisplayObject ): Boolean

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

Parameters

target: DisplayObject


resetTouch ( type: String , touches: Vector.<Touch> , shiftKey: Boolean = false , ctrlKey: Boolean = false , bubbles: Boolean = true ): Void

Parameters

type: String
touches: Vector.<Touch>
shiftKey: Boolean = false
ctrlKey: Boolean = false
bubbles: Boolean = true


stopImmediatePropagation (): Void
Inherited from Event

Prevents any other listeners from receiving the event.



stopPropagation (): Void
Inherited from Event

Prevents listeners at the next bubble stage from receiving the event.



toString (): String
Inherited from Object

native

Returns a String that describes the Object. This can be overriden to provide extra details when printing objects using trace().


Returns

String String that described the Object.

: