hitTest()
Top  Previous  Next


SWiSH Player Support
SWF5 or later - Supported Internally

Syntax
mySprite.hitTest(x, y {,shapeFlag})
mySprite.hitTest(target)

Arguments
x: The horizontal coordinate of the hit area relative to the Stage (global).

y
: The vertical coordinate of the hit area relative to the Stage (global).

shapeflag
: a Boolean value (true or false) telling the script whether to evaluate the shape of the specified Sprite (true), or just its bounding box (false). This argument can only be used if the x and y arguments are also specified. This is an optional argument and defaults to false if not specified.

target
: The target path of the hit area that may come in contact with the specified Sprite.

Returns
Nothing.

Description
Method; checks whether or not the specified Sprite comes in contact with the hit area of either the target or x and y coordinate.

Sample
The following samples apply to the mouse cursor touching the outer boundaries of a star shape named "star" inside a sprite named "mySprite"

onEnterFrame() {
  if (mySprite.hitTest(_xmouse,_ymouse,true)) {
    trace("Hey, quit touching me!");
  }

// will display "Hey, quit touching me!" in the debug window whenever the mouse cursor is moved over the star shape inside 'mySprite'


onEnterFrame() {
  if (mySprite.hitTest(_xmouse,_ymouse,false)) {
    trace("Hey, quit touching me!");
  }

// will display "Hey, quit touching me!" in the debug window whenever the mouse cursor is moved over the outer boundaries of the Sprite itself (the rectangle container holding the star shape)