GODPAPER | All Packages | All Classes | Index | Frames No Frames |
Touch

Package | starling.events
Class | public class Touch
Inheritance | Touch Object

A Touch object contains information about the presence or movement of a finger or the mouse on the screen.

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 touch

You 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

TouchEvent
TouchPhase

Public Properties

| Property | Defined By
--- | --- | ---
|  | 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
|  | 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

Public Methods

| Method | Defined By
--- | --- | ---
|  | Touch(id:int) Creates a new Touch object. | Touch
|  | clone():Touch Creates a clone of the Touch object. | Touch
|  | getLocation(space:DisplayObject, resultPoint:Point = null):Point Converts the current location of a touch to the local coordinate system of a display object. | Touch
|  | getMovement(space:DisplayObject, resultPoint:Point = null):Point Returns the movement of the touch between the current and previous location. | Touch
|  | getPreviousLocation(space:DisplayObject, resultPoint:Point = null):Point Converts the previous location of a touch to the local coordinate system of a display object. | 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

Property Detail

globalX | property

`globalX:Number`

The x-position of the touch in stage coordinates. If you change this value, the previous one will be moved to "previousGlobalX".

Implementation
`public function get globalX():Number`
`public function set globalX(value:Number):void`

globalY | property |

`globalY:Number`

The y-position of the touch in stage coordinates. If you change this value, the previous one will be moved to "previousGlobalY".

Implementation
`public function get globalY():Number`
`public function set globalY(value:Number):void`

height | property |

`height:Number`

Height of the contact area. If the device does not support detecting the pressure, the value is 1.0.

Implementation
`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.

Implementation
`public function get id():int`

phase | property |

`phase:String`

The current phase the touch is in.

Implementation
`public function get phase():String`
`public function set phase(value:String):void`

See also

TouchPhase

pressure | property |

`pressure:Number`

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

Implementation
`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.

Implementation
`public function get previousGlobalX():Number`

previousGlobalY | property |

`previousGlobalY:Number` [read-only]

The previous y-position of the touch in stage coordinates.

Implementation
`public function get previousGlobalY():Number`

tapCount | property |

`tapCount:int`

The number of taps the finger made in a short amount of time. Use this to detect double-taps / double-clicks, etc.

Implementation
`public function get tapCount():int`
`public function set tapCount(value:int):void`

target | property |

`target:DisplayObject`

The display object at which the touch occurred.

Implementation
`public function get target():DisplayObject`
`public function set target(value:DisplayObject):void`

timestamp | property |

`timestamp:Number`

The moment the touch occurred (in seconds since application start).

Implementation
`public function get timestamp():Number`
`public function set timestamp(value:Number):void`

width | property |

`width:Number`

Width of the contact area. If the device does not support detecting the pressure, the value is 1.0.

Implementation
`public function get width():Number`
`public function set width(value:Number):void`
Constructor Detail

Touch | () | Constructor

`public function Touch(id:int)`

Creates a new Touch object.

Parameters

| `id:int`

Method Detail

clone | () | method

`public function clone():Touch`

Creates a clone of the Touch object.

Returns

| `Touch`

getLocation | () | method |

`public function getLocation(space:DisplayObject, resultPoint:Point = null):Point`

Converts the current location of a touch to the local coordinate system of a display object. If you pass a 'resultPoint', the result will be stored in this point instead of creating a new object.

Parameters

| `space:DisplayObject`
| `resultPoint:Point` (default = `null`)``

Returns

| `Point`

getMovement | () | method |

`public function getMovement(space:DisplayObject, resultPoint:Point = null):Point`

Returns the movement of the touch between the current and previous location. If you pass a 'resultPoint', the result will be stored in this point instead of creating a new object.

Parameters

| `space:DisplayObject`
| `resultPoint:Point` (default = `null`)``

Returns

| `Point`

getPreviousLocation | () | method |

`public function getPreviousLocation(space:DisplayObject, resultPoint:Point = null):Point`

Converts the previous location of a touch to the local coordinate system of a display object. If you pass a 'resultPoint', the result will be stored in this point instead of creating a new object.

Parameters

| `space:DisplayObject`
| `resultPoint:Point` (default = `null`)``

Returns

| `Point`

isTouching | () | method |

`public function isTouching(target:DisplayObject):Boolean`

Indicates if the target or one of its children is touched.

Parameters

| `target:DisplayObject`

Returns

| `Boolean`

toString | () | method |

`public function toString():String`

Returns a description of the object.

Returns

| `String`

Thu Jan 16 2014, 01:11 PM +08:00