750
Chapter 7: ActionScript for Flash
Description
Method; applies the text formatting specified by textFormat to some or all of the text in a text
field.
textFormat
must be a TextFormat object that specifies the text formatting changes desired.
Only the non-null properties of textFormat are applied to the text field. Any property of
textFormat
that is set to null will not be applied. By default, all of the properties of a newly
created TextFormat object are set to
null
.
There are two types of formatting information in a TextFormat object: character level, and
paragraph level formatting. Each character in a text field might have its own character formatting
settings, such as font name, font size, bold, and italic.
For paragraphs, the first character of the paragraph is examined for the paragraph formatting
settings for the entire paragraph. Examples of paragraph formatting settings are left margin, right
margin, and indentation.
The
setTextFormat()
method changes the text formatting applied to an individual character, to
a range of characters, or to the entire body of text in a text field.
Usage 1: Applies the properties of
textFormat
to all text in the text field.
Usage 2: Applies the properties of
textFormat
to the character at position index.
Usage 3: Applies the properties of the
textFormat
parameter to the span of text from the
beginIndex parameter to the endIndex parameter.
Notice that any text inserted manually by the user, or replaced by means of
TextField.replaceSel()
, receives the text field's default formatting for new text, and not the
formatting specified for the text insertion point. To set a text field’s default formatting for new
text, use
TextField.setNewTextFormat()
.
Example
The following example sets the text format for two different strings of text. The
setTextFormat
()
method is called and applied to the
my_txt
text field.
var format1_fmt:TextFormat = new TextFormat();
format1_fmt.font = "Arial";
var format2_fmt:TextFormat = new TextFormat();
format2_fmt.font = "Courier";
var string1:String = "Sample string number one."+newline;
var string2:String = "Sample string number two."+newline;
this.createTextField("my_txt", this.getNextHighestDepth(), 0, 0, 300, 200);
my_txt.multiline = true;
my_txt.wordWrap = true;
my_txt.text = string1;
var firstIndex:Number = my_txt.length;
my_txt.text += string2;
var secondIndex:Number = my_txt.length;
my_txt.setTextFormat(0, firstIndex, format1_fmt);
my_txt.setTextFormat(firstIndex, secondIndex, format2_fmt);
Summary of Contents for FLEX
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 ...