User Guide
TextSnapshot.setSelected() 797
Example
The following example illustrates how to use this method. To use this code, place a static text field
containing the text “TextSnapshot Example” on the Stage. Add the following ActionScript to
your AS or FLA file.
Note: If characters don’t appear to be selected when you run the code, you must also place a
dynamic text field on the Stage. See “Description” in this entry.
// This example assumes that the movie clip contains
// the static text "TextSnapshot Example"
var my_snap:TextSnapshot = this.getTextSnapshot();
var count:Number = my_snap.getCount();
my_snap.setSelectColor(0xFF0000); // Set the selection color to red.
my_snap.setSelected(0, 4, true); // Select the first four characters.
my_snap.setSelected(1, 2, false); // deselect the second character (leaving
the rest selected)
var firstCharIsSelected:Boolean = my_snap.getSelected(0, 1);
var secondCharIsSelected:Boolean = my_snap.getSelected(1, 2);
var theText:String = my_snap.getSelectedText(false); // get the selected text
trace(theText); // output: Txt
trace(firstCharIsSelected); // output: true
trace(secondCharIsSelected); // output: false
When you test the SWF file, you see a colored rectangle around the specified characters.
TextSnapshot.setSelected()
Availability
Authoring: Flash MX 2004.
Playback: SWF files published for Flash Player 6 or later, playing in Flash Player 7 or later.
Usage
my_snap.setSelected(from:Number, to:Number, select:Boolean) : Void
Parameters
from
An integer that indicates the position of the first character of my_snap to select. Valid
values for
from are 0 through TextSnapshot.getCount() - 1. If from is a negative value,
0 is used.
to An integer that is 1+ the index of the last character in my_snap to be examined. Valid values
for
to are 0 through TextSnapshot.getCount(). The character indexed by the to parameter is
not included in the extracted string. If this parameter is omitted,
TextSnapshot.getCount() is
used. If this value is less than or equal to the value of
from, from+1 is used.
select A Boolean value that specifies whether the text should be selected (true) or
deselected (
false).
Returns
Nothing.