ActionScript 2.0 Language Reference |
|
|
|
| ActionScript classes > TextSnapshot > setSelected (TextSnapshot.setSelected method) | |||
Specifies a range of characters in a TextSnapshot object to be selected or not. Characters that are selected are drawn with a colored rectangle behind them, matching the bounding box of the character. The color of the bounding box is defined by TextSnapshot.setSelectColor().
To select or deselect all characters, pass a value of 0 for start and TextSnapshot.getCount() (or any very large number) for end. To specify a single character, pass a value of start + 1 for end.
Because characters are individually marked as selected, you can call this method multiple times to select multiple characters; that is, using this method does not deselect other characters that have been set by this method.
This method works correctly only with fonts that include character metric information; by default, Flash does not include this information for static text fields. Therefore, text that is selected might not appear to be selected onscreen. To ensure that all selected text appears to be selected, you can force the Flash authoring tool to include the character metric information for a font. To do this, in the library, include the font used by the static text field, and in Linkage options for the font, select Export for ActionScript.
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.
start:Number - The position of the first character to select. Valid values for start are 0 through TextSnapshot.getCount() - 1. If start is a negative value, 0 is used.
end:Number - An integer that is 1+ the index of the last character to be examined. Valid values for end are 0 through TextSnapshot.getCount(). The character indexed by the end parameter is not included in the extracted string. If you omit this parameter, TextSnapshot.getCount() is used. If the value of end is less than or equal to the value of start, start + 1 is used.
select:Boolean - A Boolean value that specifies whether the text should be selected (true) or not (false).
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. Add the following ActionScript to Frame 1 of the Timeline:
var my_snap:TextSnapshot = this.getTextSnapshot(); var count:Number = my_snap.getCount(); my_snap.setSelected(0, 4, true); my_snap.setSelected(1, 2, false); var theText:String = my_snap.getSelectedText(false); trace(theText); // Text
getCount (TextSnapshot.getCount method)
|
|
|
|