Change Text format : text format « TextField « Flash / Flex / ActionScript






Change Text format

 

package {

  import flash.display.Sprite;
  import flash.text.TextField;
  import flash.text.TextFormat;
  
  public class Main extends Sprite {
    public function Main(  ) {
      var field:TextField = new TextField(  );
      var formatter:TextFormat = new TextFormat(  );

      formatter.bold = true;       // Bold the text
      formatter.color = 0xFFFF00;  // Make the text yellow
      formatter.blockIndent = 5;   // Adjust the margin by 5 points
    
      field.setTextFormat(formatter);
      field.text = "this is sample text";
      field.setTextFormat(formatter);    // Formatting applied
      field.text = "this is new text";   // No formatting applied
      field.setTextFormat(formatter);    // Formatting reapplied
      field.text += "appended text";     // Formatting removed
    
      addChild(field);
    }
  }
}

        








Related examples in the same category

1.Formatting User-Input Text
2.Formatting a Portion of Existing 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