ActionScript 2.0 Language Reference |
|
|
|
| ActionScript classes > TextSnapshot > hitTestTextNearPos (TextSnapshot.hitTestTextNearPos method) | |||
Lets you determine which character within a TextSnapshot object is on or near the specified x, y coordinates of the movie clip containing the text in the TextSnapshot object.
If you omit or pass a value of 0 for closeDist, the location specified by the x, y coordinates must lie inside the bounding box of the TextSnapshot object.
This method works correctly only with fonts that include character metric information; however, by default, Adobe Flash does not include this information for static text fields. Therefore, the method might return -1 instead of an index value. To ensure that an index value is returned, you can force the Flash authoring tool to include the character metric information for a font. To do this, add a dynamic text field that uses that font, select Character Options for that dynamic text field, and then specify that font outlines should be embedded for at least one character. (It doesn't matter which characters you specify, nor whether they are the characters used in the static text fields.)
Availability: ActionScript 1.0; Flash Player 7 - The SWF file must be published for Flash Player 6 or later, and must be played in Flash Player 7 or later.
x:Number - The x coordinate of the movie clip that contains the text in the TextSnapshot object.
y:Number - The y coordinate of the movie clip that contains the text in the TextSnapshot object.
closeDist:Number [optional] - The maximum distance from x, y that can be searched for text. The distance is measured from the centerpoint of each character. The default value is 0.
Number - The index value of the character in the TextSnapshot object that is nearest to the specified x, y coordinate. The method returns -1 if no character is found, or if the font doesn't contain character metric information.
The following example illustrates how to use this method. To use this code, place a static text field that contains the text "TextSnapshot Example" on the Stage. In the library, include the font used by the static text field, and in Linkage options for the font, select Export for ActionScript. To test the code, run the SWF file and point the mouse pointer to the onscreen text.
var my_ts:TextSnapshot = getTextSnapshot();
this.onMouseMove = function() {
var hitIndex:Number = my_ts.hitTestTextNearPos(_xmouse, _ymouse, 0);
my_ts.setSelected(0, my_ts.getCount(), false);
if (hitIndex >= 0) {
my_ts.setSelected(hitIndex, hitIndex + 1, true);
}
};
getTextSnapshot (MovieClip.getTextSnapshot method), _x (MovieClip._x property), _y (MovieClip._y property)
|
|
|
|