TextFormat.align Property

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
TextFormat.align Property Flash 6

specifies horizontal paragraph alignment read/write
theFormat.align

Description

The string align property specifies whether text is positioned at the "left", "right", or "center" of a text field. It applies to paragraphs, which are spans of text separated by line break characters specified in code (\n, <BR>, <P>, or newline). To set the alignment for an entire text field, apply the text format by invoking TextField.setTextFormat( ) without specifying any index arguments:

this.createTextField("theField_txt", 1, 0, 0, 200, 60); theField_txt.border = true; theField_txt.text = "This is paragraph one.\nThis is paragraph two." // Create a TextFormat object format = new TextFormat(); format.align = "center"; // Center the whole field theField_txt.setTextFormat(format);

To set the alignment for the first paragraph in a text field, apply the format to the character at index 0:

theField_txt.setTextFormat(0, format);

To set the alignment for any subsequent paragraphs, apply the format to the character immediately following the newline character:

// Center the second paragraph theField_txt.setTextFormat(23, format);

To set the alignment for a range of paragraphs, apply the format using start and end index arguments that include the desired paragraphs:

theField_txt.setTextFormat(0, 24, format);

If any paragraph wraps to the next line, the specified format range must include the subsequent line's first character; otherwise, the format will not apply to the wrapped line.

If automatic word-wrapping is disabled for a text field and the text of a paragraph exceeds the width of the field, the text will be left-aligned, regardless of the setting of align.

The default align value (as contained in the TextFormat object returned by TextField.getTextFormat( )) for a text field that contains text is "left". For a text field without any text, the align value is null. For a completely new TextFormat object, it is also null, indicating that align will not be set when the format is applied to a text field:

trace(anyUnformattedField_txt.getTextFormat().align);  // Displays: "left" var format = new TextFormat(); trace(format.align);                                   // Displays: "null"

See Also

TextField.wordWrap, TextFormat.blockIndent, TextFormat.indent, TextFormat.leftMargin, TextFormat.rightMargin



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net