Formatting a Portion of Existing Text : text format « TextField « Flash / Flex / ActionScript






Formatting a Portion of Existing Text

 

package {

  import flash.display.Sprite;
  import flash.text.TextField;
  public class Main extends Sprite {
    public function Main(  ) {
      var field:TextField = new TextField(  );
      var formatter:flash.text.TextFormat = new flash.text.TextFormat(  );
      formatter.color = 0x0000FF;      // Make the text blue
      field.text="12345678900987654321asdfasdf";   
      field.setTextFormat(formatter,0,10);                               
      field.setTextFormat( formatter,10,20); 
      addChild(field);
    }
  }
}

        








Related examples in the same category

1.Change Text format
2.Formatting User-Input Text
3.Setting a Text Field's Font
4.Use the TextFormat object's color and underline properties
5.Embedded font warning: Bold and italic require separate fonts
6.setTextFormat( ) does not apply to future text assignments
7.To set the alignment for the first paragraph in the text field only, we apply the format to the first character in the first paragraph, which resides at index 0:
8.To set the alignment for the second paragraph only, we apply the format to the first character in the second paragraph, which resides at index 23:
9.To set the alignment for a range of paragraphs, we apply the format using beginIndex and endIndex arguments that include the desired paragraphs:
10.Apply alignment formatting to the entire span of characters in the second paragraph.
11.Retrieving formatting information for a span of characters
12.If a specific format (e.g., font, bold, or italic) is not the same for all characters in a specified span, the corresponding variable of the TextFormat object for that span will be null
13.Default formatting for text fields
14.Set text format by searching the substring in textfield
15.The format for an empty TextField object is specified by assigning a TextFormat object to the TextField object's defaultTextFormat variable
16.Two formats