beautypg.com

Text.settextattr() – Adobe Extending Flash Professional CS4 User Manual

Page 469

background image

447

EXTENDING FLASH CS4 PROFESSIONAL

Text object

fl.getDocumentDOM().selection[0].selectionStart = 11;

fl.getDocumentDOM().selection[0].selectionEnd = 18;

var s = fl.getDocumentDOM().selection[0].selectionStart;

var e = fl.getDocumentDOM().selection[0].selectionEnd;

fl.getDocumentDOM().setElementTextAttr('bold', true, s, e);

fl.getDocumentDOM().setElementTextAttr("fillColor", "#00ff00", s, e);

text.setTextAttr()

Availability
Flash MX 2004.

Usage

text.setTextAttr(attrName, attrValue [, startIndex [, endIndex]])

Parameters

attrName

A string that specifies the name of the TextAttrs object property to change.

attrValue

The value for the TextAttrs object property.

For a list of possible values for

attrName

and

attrValue

, see the Property summary for the

TextAttrs object

.

startIndex

An integer that is the index (zero-based) of the first character in the array. This parameter is optional.

endIndex

An integer that specifies the index of the end point in the selected text string, which starts at startIndex and

goes up to, but does not include, endIndex. This parameter is optional.

Returns
Nothing.

Description
Method; sets the attribute specified by the attrName parameter associated with the text identified by startIndex and
endIndex to the value specified by attrValue. This method can be used to change attributes of text that might span
TextRun elements (see

TextRun object

), or that are portions of existing TextRun elements. Using it may change the

position and number of TextRun elements within this object’s

text.textRuns

array (see

text.textRuns

).

If you omit the optional parameters, the method uses the entire Text object’s character range. If you specify only
startIndex, the range is a single character at that position. If you specify both startIndex and endIndex, the range starts
from startIndex and goes up to, but does not include, the character located at endIndex.

Example
The following example sets the selected text field to italic:

fl.getDocumentDOM().selection[0].setTextAttr("italic", true);

The following example sets the size of the third character to 10:

fl.getDocumentDOM().selection[0].setTextAttr("size", 10, 2);

The following example sets the color to red for the third through the eighth character of the selected text:

fl.getDocumentDOM().selection[0].setTextAttr("fillColor", 0xff0000, 2, 8);