| Package | starling.events |
| Class | public class Touch |
| Inheritance | Touch Object |
You receive objects of this type from a TouchEvent. When such an event is triggered, you can query it for all touches that are currently present on the screen. One touch object contains information about a single touch; it always transitions through a series of TouchPhases. Have a look at the TouchPhase class for more information.
The position of a touchYou can get the current and previous position in stage coordinates with the corresponding properties. However, you'll want to have the position in a different coordinate system most of the time. For this reason, there are methods that convert the current and previous touches into the local coordinate system of any object.
See also
| Property | Defined By | ||
|---|---|---|---|
| cancelled : Boolean Indicates if the touch has been cancelled, which may happen when the app moves into
the background ('Event.DEACTIVATE'). | Touch | ||
| duration : Number [read-only] If the touch is hovering, returns the time (in seconds) since the touch was created;
afterwards, the time since the touch was in phase 'BEGAN'. | Touch | ||
| globalX : Number The x-position of the touch in stage coordinates. | Touch | ||
| globalY : Number The y-position of the touch in stage coordinates. | Touch | ||
| height : Number Height of the contact area. | Touch | ||
| id : int [read-only] The identifier of a touch. | Touch | ||
| phase : String The current phase the touch is in. | Touch | ||
| pressure : Number A value between 0.0 and 1.0 indicating force of the contact with the device. | Touch | ||
| previousGlobalX : Number [read-only] The previous x-position of the touch in stage coordinates. | Touch | ||
| previousGlobalY : Number [read-only] The previous y-position of the touch in stage coordinates. | Touch | ||
| startGlobalX : Number [read-only] The x-position of the touch when it was in 'TouchPhase.BEGAN', in stage coordinates. | Touch | ||
| startGlobalY : Number [read-only] The y-position of the touch when it was in 'TouchPhase.BEGAN', in stage coordinates. | Touch | ||
| tapCount : int The number of taps the finger made in a short amount of time. | Touch | ||
| target : DisplayObject The display object at which the touch occurred. | Touch | ||
| timestamp : Number The moment the touch occurred (in seconds since application start). | Touch | ||
| width : Number Width of the contact area. | Touch | ||
| Method | Defined By | ||
|---|---|---|---|
Touch(id:int) Creates a new Touch object. | Touch | ||
Creates a clone of the Touch object. | Touch | ||
getLocation(space:DisplayObject, out:Point = null):Point Converts the current location of a touch to the local coordinate system of a display
object. | Touch | ||
getMovement(space:DisplayObject, out:Point = null):Point Returns the movement of the touch between the current and previous location. | Touch | ||
getMovementSinceStart(space:DisplayObject, out:Point = null):Point Returns the movement of the touch between the current and the start location. | Touch | ||
getPreviousLocation(space:DisplayObject, out:Point = null):Point Converts the previous location of a touch to the local coordinate system of a display
object. | Touch | ||
getStartLocation(space:DisplayObject, out:Point = null):Point Converts the start location of a touch (i.e. | Touch | ||
isTouching(target:DisplayObject):Boolean Indicates if the target or one of its children is touched. | Touch | ||
toString():String Returns a description of the object. | Touch | ||
| cancelled | property |
cancelled:BooleanIndicates if the touch has been cancelled, which may happen when the app moves into the background ('Event.DEACTIVATE').
The default value is false.
public function get cancelled():Boolean public function set cancelled(value:Boolean):void| duration | property |
duration:Number [read-only] If the touch is hovering, returns the time (in seconds) since the touch was created; afterwards, the time since the touch was in phase 'BEGAN'.
public function get duration():Number| globalX | property |
globalX:NumberThe x-position of the touch in stage coordinates. If you change this value, the previous one will be moved to "previousGlobalX".
public function get globalX():Number public function set globalX(value:Number):void| globalY | property |
globalY:NumberThe y-position of the touch in stage coordinates. If you change this value, the previous one will be moved to "previousGlobalY".
public function get globalY():Number public function set globalY(value:Number):void| height | property |
height:NumberHeight of the contact area. If the device does not support detecting the pressure, the value is 1.0.
public function get height():Number public function set height(value:Number):void| id | property |
id:int [read-only] The identifier of a touch. '0' for mouse events, an increasing number for touches.
public function get id():int| phase | property |
phase:StringThe current phase the touch is in.
public function get phase():String public function set phase(value:String):voidSee also
| pressure | property |
pressure:NumberA value between 0.0 and 1.0 indicating force of the contact with the device. If the device does not support detecting the pressure, the value is 1.0.
public function get pressure():Number public function set pressure(value:Number):void| previousGlobalX | property |
previousGlobalX:Number [read-only] The previous x-position of the touch in stage coordinates.
public function get previousGlobalX():Number| previousGlobalY | property |
previousGlobalY:Number [read-only] The previous y-position of the touch in stage coordinates.
public function get previousGlobalY():Number| startGlobalX | property |
startGlobalX:Number [read-only] The x-position of the touch when it was in 'TouchPhase.BEGAN', in stage coordinates. (Or, if the touch is in phase 'HOVER', the x-position when it first appeared.)
public function get startGlobalX():Number| startGlobalY | property |
startGlobalY:Number [read-only] The y-position of the touch when it was in 'TouchPhase.BEGAN', in stage coordinates. (Or, if the touch is in phase 'HOVER', the y-position when it first appeared.)
public function get startGlobalY():Number| tapCount | property |
tapCount:intThe number of taps the finger made in a short amount of time. Use this to detect double-taps / double-clicks, etc.
public function get tapCount():int public function set tapCount(value:int):void| target | property |
target:DisplayObjectThe display object at which the touch occurred.
public function get target():DisplayObject public function set target(value:DisplayObject):void| timestamp | property |
timestamp:NumberThe moment the touch occurred (in seconds since application start).
public function get timestamp():Number public function set timestamp(value:Number):void| width | property |
width:NumberWidth of the contact area. If the device does not support detecting the pressure, the value is 1.0.
public function get width():Number public function set width(value:Number):void| Touch | () | Constructor |
public function Touch(id:int)Creates a new Touch object.
Parametersid:int |
| clone | () | method |
| getLocation | () | method |
public function getLocation(space:DisplayObject, out:Point = null):Point Converts the current location of a touch to the local coordinate system of a display
object. If you pass an out-point, the result will be stored in this point
instead of creating a new object.
Parameters
space:DisplayObject | |
out:Point (default = null) |
Point |
| getMovement | () | method |
public function getMovement(space:DisplayObject, out:Point = null):Point Returns the movement of the touch between the current and previous location.
If you pass an out-point, the result will be stored in this point instead
of creating a new object.
Parameters
space:DisplayObject | |
out:Point (default = null) |
Point |
| getMovementSinceStart | () | method |
public function getMovementSinceStart(space:DisplayObject, out:Point = null):Point Returns the movement of the touch between the current and the start location.
If you pass an out-point, the result will be stored in this point instead
of creating a new object.
Parameters
space:DisplayObject | |
out:Point (default = null) |
Point |
| getPreviousLocation | () | method |
public function getPreviousLocation(space:DisplayObject, out:Point = null):Point Converts the previous location of a touch to the local coordinate system of a display
object. If you pass an out-point, the result will be stored in this point
instead of creating a new object.
Parameters
space:DisplayObject | |
out:Point (default = null) |
Point |
| getStartLocation | () | method |
public function getStartLocation(space:DisplayObject, out:Point = null):Point Converts the start location of a touch (i.e. when it entered 'TouchPhase.BEGAN') to
the local coordinate system of a display object. If you pass an out-point,
the result will be stored in this point instead of creating a new object.
Parameters
space:DisplayObject | |
out:Point (default = null) |
Point |
| isTouching | () | method |
public function isTouching(target:DisplayObject):BooleanIndicates if the target or one of its children is touched.
Parameters
target:DisplayObject |
Boolean |
| toString | () | method |
public function toString():StringReturns a description of the object.
ReturnsString |