
MovieClip.lineStyle() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
668
|
ActionScript Language Reference
always describe a point using Stage coordinates. See MovieClip.localToGlobal() for infor-
mation on converting clip coordinates to Stage coordinates. In clip-versus-clip detection,
the coordinates of clips on different timelines are automatically converted to global (i.e.,
Stage) coordinates.
Example
This example shows how to detect the intersection of two circles manually, without using
hitTest():
// Check the distance between two circular clips on both axes.
var deltaX = clip1._x - clip2._x; // Horizontal distance
var deltaY = clip1._y - clip2._y; // Vertical distance
// Store the radius of each circle in a convenient property.
var radius1 = clip1._width / 2;
var radius2 = clip2._width / 2;
// If the distance between the circles' centers squared is less
// than or equal to the total length of the two radii squared,
// an intersection occurs.
if ((deltaX * deltaX) + (deltaY * deltaY)
<= (radius1 + radius2) * (radius1 + radius2)) {
trace("intersecting");
} else {
trace("not intersecting");
}
Here we check whether paddle_mc intersects ball_mc using hitTest():
if (paddle_mc.hitTest("ball_mc")) {
trace("The paddle hit the ball.");
}
Here we check whether the mouse pointer is over an occupied pixel within house_mc’s
contour. Notice ...