
MovieClip.hitTest() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
666
|
ActionScript Language Reference
// Define a button handler for the button clip
button_mc.onPress = function () {
trace("thank you for clicking");
}
// Make a clip to be the button clip's hit area, and
// put it inside the button clip
button_mc.createEmptyMovieClip("hitarea_mc", 2);
// Set the hit area rectangle to be twice the size of the button text
var x1 = -button_mc.button_txt._width / 2;
var y1 = -button_mc.button_txt._height / 2;
var x2 = x1 + button_mc.button_txt._width * 2;
var y2 = y1 + button_mc.button_txt._height * 2;
// Draw the hit area rectangle
button_mc.hitarea_mc.moveTo(x1, y1);
button_mc.hitarea_mc.beginFill(0x000000);
button_mc.hitarea_mc.lineTo(x2, y1);
button_mc.hitarea_mc.lineTo(x2, y2);
button_mc.hitarea_mc.lineTo(x1, y2);
button_mc.hitarea_mc.lineTo(x1, y1);
button_mc.hitarea_mc.endFill();
// Make the hit clip invisible
button_mc.hitarea_mc._visible = false;
// Assign the drawn clip as the button's hit area
button_mc.hitArea = button_mc.hitarea_mc;
See Also
The Button class, MovieClip.enabled, MovieClip.hitTest(), MovieClip.useHandCursor; “Using
Movie Clips as Buttons” in Chapter 13
MovieClip.hitTest() Method
check if a point or another clip intercept a given clip
Flash 5
mc.hitTest(x, y, shapeFlag)
mc.hitTest(target)
Arguments
x The horizontal coordinate ...