Table of Contents

TextField.autoSize Property Flash 6

matches the text field's bounding rectangle size to its text read/write
theField.autoSize

Description

The string autoSize property can make a text field's bounding rectangle match the size of the text it contains. Use autoSize to ensure that a text field is large enough to display its assigned text or to allow a text field to change size dynamically when its content changes (due to user input or reassignment of the text property). For example, here we create a TextField, title_txt, that contains the text "Contact Information". We don't know the size of the text, so we can't set the width of title_txt accurately:

// The width and height of 80 and 20 are just a guess...
this.createTextField("title_txt", 1, 0, 0, 80, 20);
title_txt.text = "Contact Information";
title_txt.border = true;

By setting the autoSize property to "left", we guarantee that the words "Contact Information" will be visible:

title_txt.autoSize = "left";

The autoSize property has four possible values: "none" (the default), "left", "right", and "center". Generally, these dictate the direction in which theField should expand or contract to fit its text, where "none" means don't resize, "left" means resize right and bottom, "right" means resize left and bottom, and "center" means resize evenly on both sides and bottom. When assigned a Boolean value, autoSize interprets false as a synonym for "none" and true as a synonym for "left". However, autoSize has important interactions with the multiline and wordWrap properties. Table 18-22 shows the behavior of autoSize in relation to multiline and wordWrap; read the table left to right to see which settings cause text field edges to resize. Note that the default values for both multiline and wordWrap are false.

Table 18-22. The autoSize property behavior

autoSize

multiline

wordWrap

Resize right?

Resize left?

Resize bottom?

false or "none"

true or false

true or false

no

no

no

true or "left"

false

false

yes

no

no

true or "left"

true

false

yes

no

yes (only at linefeeds)

true or "left"

false

true

no

no

yes (only at text overflow)

true or "left"

true

true

no

no

yes (at text overflow and linefeeds)

"right"

false

false

no

yes

no

"right"

true

false

no

yes

yes (only at linefeeds)

"right"

false

true

no

no

yes (only at text overflow)

"right"

true

true

no

no

yes (at text overflow and linefeeds)

"center"

false

false

yes

yes

no

"center"

true

false

yes

yes

yes (only at linefeeds)

"center"

false

true

no

no

yes (only at text overflow)

"center"

true

true

no

no

yes (at text overflow and linefeeds)

The autoSize property overrides any absolute sizes specified by createTextField( ), _height, or _width.

Example

The following code causes title_txt's bounding rectangle to grow or shrink on both the left and right sides as text is added to it or removed from it:

this.createTextField("title_txt", 1, 0, 0, 0, 0);
title_txt.text = "Title Goes Here";
title_txt.border = true;
title_txt.autoSize = "center";

The following code gives paragraph_txt a fixed width of 100 and an expandable bottom border:

this.createTextField("paragraph_txt", 1, 0, 0, 100, 0);
paragraph_txt.text = "The following sentence is a pangram.\n\n"
                     + "The quick brown fox jumps over a lazy dog.";
paragraph_txt.border = true;
paragraph_txt.multiline = true;
paragraph_txt.wordWrap = true;
paragraph_txt.autoSize = "left";

See Also

TextField._height, TextField.multiline, TextField._width, TextField.wordWrap


Table of Contents