Max-Mov > MovieClip.hitTest

MovieClip.hitTest

Syntax

anyMovieClip.hitTest(x, y, shapeFlag);
anyMovieClip.hitTest(target); 

Arguments

x The x coordinate of the hit area on the Stage.

y The y coordinate of the hit area on the Stage.

The x and y coordinates are defined in the global coordinate space.

target The target path of the hit area that may intersect or overlap with the instance specified by anyMovieClip. The target usually represents a button or text-entry field.

shapeFlag A Boolean value specifying whether to evaluate the entire shape of the specified instance (true), or just the bounding box (false). This argument can only be specified if the hit area is identified using x and y coordinate arguments.

Description

Method; evaluates the instance specified by anyMovieClip to see if it overlaps or intersects with the hit area identified by the target or x and y coordinate arguments.

Usage 1compares the x and y coordinates to the shape or bounding box of the specified instance, according to the shapeFlag setting. If shapeFlag is set to true, only the area actually occupied by the instance on the Stage is evaluated, and if x and y overlap at any point, a value of true is returned. This is useful for determining if the movie clip is within a specified hit, or hotspot, area.

Usage 2 evaluates the bounding boxes of the target and specified instance, and returns true if they overlap or intersect at any point.

Player

Flash 5 or later.

Example

The following example uses hitTest with the x_mouse and y_mouse properties to determine whether the mouse is over the target's bounding box:

if (hitTest( _root._xmouse, _root._ymouse, false));

The following example uses hitTest to determine if the movie clip ball overlaps or intersects with the movie clip square:

if(_root.ball, hittest(_root.square)){
	trace("ball intersects square");
}

See also

MovieClip.localToGlobal
MovieClip.globalToLocal
MovieClip.getBounds