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
An integer that indicates the position of the first character of
from
values for
are 0 through
from
0 is used.
An integer that is 1+ the index of the last character in
to
for
are 0 through
to
not included in the extracted string. If this parameter is omitted,
used. If this value is less than or equal to the value of
A Boolean value that specifies whether the text should be selected (
select
deselected (
false
Returns
Nothing.
TextSnapshot.getCount()
TextSnapshot.getCount()
).
my_snap
- 1. If
from
to be examined. Valid values
my_snap
. The character indexed by the
TextSnapshot.getCount()
,
is used.
from
from+1
TextSnapshot.setSelected()
to select. Valid
is a negative value,
parameter is
to
) or
true
797
is
Need help?
Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?