isNearTarget(target,dx,dy)
Top  Previous  Next


SWiSH Player Support
SWF4 or later - Supported Internally

Syntax
isNearTarget(targetname [,a] [,b])

Arguments
targetname: Name of the Sprite / Movie Clip whose proximity we are testing.
a: X near boundary or radius if parameter b omitted.
b: Y near boundary.

Returns
Boolean true if the two Objects are near each other.
Boolean false otherwise.

Description
Returns true if the current Sprite / Object / Movie Clip is 'near' the Sprite / Object / Movie Clip defined by targetname. This targetname must be defined using slash notation. The _target property of another Sprite / Object is also an allowable parameter.

Calculation is defined with respect to the center points of the Sprites / Objects (not the anchor point).
The meaning of 'near' depends on the supplied Arguments.
If no Arguments are defined, the Objects are considered 'near' if their bounding rectangles overlap.
If only the 'a' parameter is defined, the Objects are considered 'near' if the distance between their centers is less than the radius defined by the 'a' parameter.
If 'a' and 'b' Arguments are defined, the Objects are considered 'near' if abs(x1 - x2) < a and abs(y1 - y2) < b
x1, y1 is the center point of one of the Objects, x2, y2 is the center point of the other Object.

Sample
Two shapes exist in the Movie, s1 and s2. The following script is included for s1:

onEnterFrame() {
    if (isNearTarget("/s2", 50, 50)) { // _root.s2._target can be used in place of "/s2"
      this._xscale = 150;   // s1 gets fat when it is near s2.
    }
 else {
      this._xscale = 100;
    }

}


See Also
isNearTarget(), isNearThis() and _target.