Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TouchEvent

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:

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:

touch:Touch = touchEvent.getTouch(this);

@see Touch @see TouchPhase

Hierarchy

Index

Constructors

constructor

  • new TouchEvent(type: string, touches?: Vector<Touch>, shiftKey?: boolean, ctrlKey?: boolean, bubbles?: boolean): TouchEvent

Properties

bubbles

bubbles: boolean

Indicates if event will bubble.

ctrlKey

ctrlKey: boolean

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

currentTarget

currentTarget: EventDispatcher

The object the event is currently bubbling at.

data

data: any

Arbitrary data that is attached to the event.

shiftKey

shiftKey: boolean

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

target

The object that dispatched the event.

timestamp

timestamp: number

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

touches

touches: Vector<Touch>

All touches that are currently available.

type

type: string

A string that identifies the event.

Static ADDED

ADDED: string

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

Static ADDED_TO_STAGE

ADDED_TO_STAGE: string

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

Static CANCEL

CANCEL: string

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

Static CHANGE

CHANGE: string

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

Static CLOSE

CLOSE: string

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

Static COMPLETE

COMPLETE: string

Event type that may be used whenever something finishes.

Static CONTEXT3D_CREATE

CONTEXT3D_CREATE: string

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

Static ENTER_FRAME

ENTER_FRAME: string

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

Static FATAL_ERROR

FATAL_ERROR: string

Event type that is dispatched by the Starling instance when it encounters a problem from which it cannot recover, e.g. a lost device context.

Static IO_ERROR

IO_ERROR: string

Event type that is dispatched by the AssetManager when a file/url cannot be loaded.

Static OPEN

OPEN: string

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

Static PARSE_ERROR

PARSE_ERROR: string

Event type that is dispatched by the AssetManager when an xml or json file couldn't be parsed.

Static READY

READY: string

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

Static REMOVED

REMOVED: string

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

Static REMOVED_FROM_STAGE

REMOVED_FROM_STAGE: string

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

Static REMOVE_FROM_JUGGLER

REMOVE_FROM_JUGGLER: string

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

Static RENDER

RENDER: string

Event type that is dispatched by the Starling instance directly before rendering.

Static RESIZE

RESIZE: string

Event type for a resized Flash Player.

Static ROOT_CREATED

ROOT_CREATED: string

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

Static SCROLL

SCROLL: string

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

Static SECURITY_ERROR

SECURITY_ERROR: string

Event type that is dispatched by the AssetManager when a file/url cannot be loaded.

Static SELECT

SELECT: string

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

Static TEXTURES_RESTORED

TEXTURES_RESTORED: string

Event type that is dispatched by the AssetManager after a context loss.

Static TOUCH

TOUCH: string

Event type for touch or mouse input.

Static TRIGGERED

TRIGGERED: string

Event type for a triggered button.

Static UPDATE

UPDATE: string

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

Methods

Private dispatch

getTouch

  • 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.

    • Optional phase: string

      The phase the touch must be in, or null if you don't care.

    • Optional id: number

      The ID of the requested touch, or -1 if you don't care.

    Returns Touch

getTouches

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

    Parameters

    Returns Vector<Touch>

Protected get_ctrlKey

  • get_ctrlKey(): boolean

Protected get_shiftKey

  • get_shiftKey(): boolean

Protected get_timestamp

  • get_timestamp(): number

Protected get_touches

  • get_touches(): Vector<Touch>

interactsWith

stopImmediatePropagation

  • stopImmediatePropagation(): void

stopPropagation

  • stopPropagation(): void

toString

  • toString(): string

Generated using TypeDoc