Packagestarling.events
Classpublic class TouchEvent
InheritanceTouchEvent Inheritance Event Inheritance 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

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
 PropertyDefined By
 Inheritedbubbles : 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
 InheritedcurrentTarget : EventDispatcher
[read-only] The object the event is currently bubbling at.
Event
 Inheriteddata : 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
 Inheritedtarget : 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
 Inheritedtype : String
[read-only] A string that identifies the event.
Event
Public Methods
 MethodDefined By
  
TouchEvent(type:String, touches:Vector.<Touch> = null, 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, out:Vector.<Touch> = null):Vector.<Touch>
Returns a list of touches that originated over a certain target.
TouchEvent
  
Indicates if a target is currently being touched or hovered over.
TouchEvent
 Inherited
Prevents any other listeners from receiving the event.
Event
 Inherited
Prevents listeners at the next bubble stage from receiving the event.
Event
 Inherited
toString():String
Returns a description of the event, containing type and bubble information.
Event
Public Constants
 ConstantDefined By
 InheritedADDED : String = added
[static] Event type for a display object that is added to a parent.
Event
 InheritedADDED_TO_STAGE : String = addedToStage
[static] Event type for a display object that is added to the stage
Event
 InheritedCANCEL : String = cancel
[static] An event type to be utilized in custom events.
Event
 InheritedCHANGE : String = change
[static] An event type to be utilized in custom events.
Event
 InheritedCLOSE : String = close
[static] An event type to be utilized in custom events.
Event
 InheritedCOMPLETE : String = complete
[static] Event type that may be used whenever something finishes.
Event
 InheritedCONTEXT3D_CREATE : String = context3DCreate
[static] Event type for a (re)created stage3D rendering context.
Event
 InheritedENTER_FRAME : String = enterFrame
[static] Event type for a display object that is entering a new frame.
Event
 InheritedFATAL_ERROR : String = fatalError
[static] Event type that is dispatched by the Starling instance when it encounters a problem from which it cannot recover, e.g.
Event
 InheritedIO_ERROR : String = ioError
[static] Event type that is dispatched by the AssetManager when a file/url cannot be loaded.
Event
 InheritedOPEN : String = open
[static] An event type to be utilized in custom events.
Event
 InheritedPARSE_ERROR : String = parseError
[static] Event type that is dispatched by the AssetManager when an xml or json file couldn't be parsed.
Event
 InheritedREADY : String = ready
[static] An event type to be utilized in custom events.
Event
 InheritedREMOVED : String = removed
[static] Event type for a display object that is removed from its parent.
Event
 InheritedREMOVED_FROM_STAGE : String = removedFromStage
[static] Event type for a display object that is removed from the stage.
Event
 InheritedREMOVE_FROM_JUGGLER : String = removeFromJuggler
[static] Event type for an animated object that requests to be removed from the juggler.
Event
 InheritedRENDER : String = render
[static] Event type that is dispatched by the Starling instance directly before rendering.
Event
 InheritedRESIZE : String = resize
[static] Event type for a resized Flash Player.
Event
 InheritedROOT_CREATED : String = rootCreated
[static] Event type that indicates that the root DisplayObject has been created.
Event
 InheritedSCROLL : String = scroll
[static] An event type to be utilized in custom events.
Event
 InheritedSECURITY_ERROR : String = securityError
[static] Event type that is dispatched by the AssetManager when a file/url cannot be loaded.
Event
 InheritedSELECT : String = select
[static] An event type to be utilized in custom events.
Event
 InheritedSKIP_FRAME : String = skipFrame
[static] Event type for a frame that is skipped because the display list did not change.
Event
 InheritedTEXTURES_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
 InheritedTRIGGERED : String = triggered
[static] Event type for a triggered button.
Event
 InheritedUPDATE : String = update
[static] An event type to be utilized in custom events.
Event
Property Detail
ctrlKeyproperty
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
shiftKeyproperty 
shiftKey:Boolean  [read-only]

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


Implementation
    public function get shiftKey():Boolean
timestampproperty 
timestamp:Number  [read-only]

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


Implementation
    public function get timestamp():Number
touchesproperty 
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> = null, shiftKey:Boolean = false, ctrlKey:Boolean = false, bubbles:Boolean = true)

Creates a new TouchEvent instance.

Parameters
type:String
 
touches:Vector.<Touch> (default = null)
 
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, out:Vector.<Touch> = null):Vector.<Touch>

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

target:DisplayObject
 
phase:String (default = null)
 
out: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
TOUCHConstant
public static const TOUCH:String = touch

Event type for touch or mouse input.