TextFormat.leftMargin Property | Flash 6 |
specifies the margin to the left of a paragraph | read/write |
The integer leftMargin property specifies the horizontal distance between the left border of a text field and the left edge of a paragraph, in pixels. Negative values for leftMargin are converted to 0 by ActionScript. Note that regardless of the value of leftMargin, Flash automatically adds a small gutter between text and a text field's border. There is no way to align text perfectly flush with the border of a text field. The leftMargin and rightMargin properties can be used simultaneously on the same paragraph.
To set the left margin for an entire text field, invoke TextField.setTextFormat( ) without specifying any index arguments:
this.createTextField("theField_txt", 1, 0, 0, 200, 40); theField_txt.border = true; theField_txt.text = "This is paragraph one.\nThis is paragraph two." theField_txt.wordWrap = true; // Create a TextFormat object format = new TextFormat(); format.leftMargin = 10; // Apply a 10-pixel left margin to the whole field theField_txt.setTextFormat(format);
To set the left margin 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 left margin for any subsequent paragraphs, apply the format to the character immediately following the newline character:
theField_txt.setTextFormat(23, format);
To set the left margin 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.
The blockIndent and leftMargin properties are cumulative; for example if leftMargin is 15 and blockIndent for a paragraph is 10, that paragraph will be indented a total of 25 pixels. Hence, the leftMargin property can be thought of as a field layout tool, while blockIndent can be thought of as a paragraph layout tool.
The default leftMargin value (as contained in the TextFormat object returned by TextField.getTextFormat( )) for a text field that contains text is 0. For a text field without any text, the leftMargin value is null. For a completely new TextFormat object, it is also null, indicating that leftMargin will not be set when the format is applied to a text field:
trace(anyUnformattedField_txt.getTextFormat().leftMargin); // Displays: 0 var format = new TextFormat(); trace(format.leftMargin); // Displays: "null"
TextFormat.blockIndent, TextFormat.rightMargin