Package | starling.events |
Class | public class TouchEvent |
Inheritance | TouchEvent Event Object |
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
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.
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
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 |
Method | Defined By | ||
---|---|---|---|
TouchEvent(type:String, touches:Vector.<Touch> = null, shiftKey:Boolean = false, ctrlKey:Boolean = false, bubbles:Boolean = true) Creates a new TouchEvent instance. | TouchEvent | ||
Returns a touch that originated over a certain target. | TouchEvent | ||
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 |
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 | ||
FATAL_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 | ||
IO_ERROR : String = ioError [static] Event type that is dispatched by the AssetManager when a file/url cannot be loaded. | Event | ||
OPEN : String = open [static] An event type to be utilized in custom events. | Event | ||
PARSE_ERROR : String = parseError [static] Event type that is dispatched by the AssetManager when an xml or json file couldn't
be parsed. | Event | ||
READY : String = ready [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 | ||
RENDER : String = render [static] Event type that is dispatched by the Starling instance directly before rendering. | 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 | ||
SECURITY_ERROR : String = securityError [static] Event type that is dispatched by the AssetManager when a file/url cannot be loaded. | Event | ||
SELECT : String = select [static] An event type to be utilized in custom events. | Event | ||
SKIP_FRAME : String = skipFrame [static] Event type for a frame that is skipped because the display list did not change. | 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 | ||
UPDATE : String = update [static] An event type to be utilized in custom events. | Event |
ctrlKey | property |
ctrlKey:Boolean
[read-only] Indicates if the ctrl key was pressed when the event occurred. (Mac OS: Cmd or Ctrl)
public function get ctrlKey():Boolean
shiftKey | property |
shiftKey:Boolean
[read-only] Indicates if the shift key was pressed when the event occurred.
public function get shiftKey():Boolean
timestamp | property |
timestamp:Number
[read-only] The time the event occurred (in seconds since application launch).
public function get timestamp():Number
touches | property |
touches:Vector.<Touch>
[read-only] All touches that are currently available.
public function get touches():Vector.<Touch>
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.
Parameterstype:String | |
touches:Vector.<Touch> (default = null )
| |
shiftKey:Boolean (default = false )
| |
ctrlKey:Boolean (default = false )
| |
bubbles:Boolean (default = true )
|
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.
|
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 )
|
Vector.<Touch> |
interactsWith | () | method |
public function interactsWith(target:DisplayObject):Boolean
Indicates if a target is currently being touched or hovered over.
Parameters
target:DisplayObject |
Boolean |
TOUCH | Constant |
public static const TOUCH:String = touch
Event type for touch or mouse input.