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.
Summary of Contents for FLEX-FLEX ACTIONSCRIPT LANGUAGE
Page 1: ...Flex ActionScript Language Reference...
Page 8: ......
Page 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0...
Page 76: ......
Page 133: ...break 133 See also for for in do while while switch case continue throw try catch finally...
Page 135: ...case 135 See also break default strict equality switch...
Page 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while...
Page 808: ...808 Chapter 7 ActionScript for Flash...
Page 810: ...810 Appendix A Deprecated Flash 4 operators...
Page 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code...
Page 816: ...816 Appendix B Keyboard Keys and Key Code Values...
Page 822: ...822 Index...