User Guide

974 Chapter 2: ActionScript Language Reference
TextSnapshot.setSelectColor()
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.setSelectColor(hexColor:Number);
Parameters
hexColor
The color used for the border placed around characters that have been selected by the
corresponding TextSnapshot.setSelected() command, expressed in
0xRRGGBB format.
Returns
Nothing.
Description
Method; specifies the color to use when highlighting characters that have been selected with the
TextSnapshot.setSelected() command. The color is always opaque; you cant specify a
transparency value.
This method functions correctly only for fonts that include character metric information; by
default, Flash does not include this information for static text fields. In some cases, this behavior
means that the method returns -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 doesnt matter which character(s) you specify, nor even if they are the characters used
in the static text fields in question.
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