O'Reilly logo

ActionScript: The Definitive Guide by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

MovieClip.hitTest( ) Method — check whether a point is in a clip or two clips intersect

Availability

Flash 5

Synopsis

mc.hitTest(x, y, shapeFlag)
mc.hitTest(target)

Arguments

x

The horizontal coordinate of the point to test.

y

The vertical coordinate of the point to test.

shapeFlag

An optional Boolean value indicating whether the collision test should detect against the bounding box of mc (false) or the actual pixels of mc (true). Defaults to false if not supplied. Note that shapeFlag may be used only with the x and y arguments, not the target argument. It is meaningful only when mc has an irregular contour or a hole like a donut; it has no effect if mc is a solid rectangular object.

target

A string indicating the path to the movie clip to test for collision with mc. Because movie clip references are converted to paths when used in a string context, target may also be a movie clip object reference, as in mc .hitTest(ball) versus mc .hitTest("ball").

Returns

A Boolean indicating the result of the collision-detection test. The result is true under any of the following circumstances:

  • The point (x, y) on the main Stage intersects with any occupied pixel of mc. An occupied pixel is one that contains a visual element, such as a shape or text.

  • The shapeFlag property is false and the point (x, y) on the main Stage intersects with any pixel in the bounding box of mc. The bounding box of mc is the smallest rectangle that can encompass every occupied pixel of mc.

  • Any pixel in the bounding box of target ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required