3

I need to realize textbox autoresizing in actionscript3(IDE - adobe flash pro cs3). For example my textarea is in width 100 px, user has been wrote in it something, that is bigger than 100 px, then my textbox should become increasingly. any ideas?

Also I can't realize multiline option: when the text goes beyond the textbox, it starts to scroll. In line type I've chosen 'multiline'.

thanks

dark
  • 167
  • 1
  • 6
  • 17

3 Answers3

4

try this:

textfield.autoSize = "left";
textfield.multiline = true;
textfield.wordWrap = true;

Hope it helps, Rob

robertp
  • 3,557
  • 1
  • 20
  • 13
1

If you want to resize textfield automaticaly you can use textfield.autoSize property.

Wnen you are using multiline textfield, then setting

textfield.autoSize = TextFieldAutoSize.LEFT; 

will align text to left and resize field vertically. If you use single line text field, it will resize to the right.

Bartek
  • 1,986
  • 1
  • 14
  • 21
0

The TextField's .autosize property is great for sizing dynamic text fields when you already know the text string (but mind the .multiline and .wordwrap properties), but won't be helpful for input text fields.

For input text, I'd suggest listening for the Event.CHANGE event, then updating the width/height based on the number of lines, the .textWidth, or TextLineMetrics info (e.g. myTextField.getLineMetrics).

Here's a quick example:

var myField:TextField = new TextField();
myField.x = 10;
myField.y = 10;
myField.width = 100;
myField.height = 20;
myField.border = true;
myField.type = TextFieldType.INPUT;
myField.addEventListener(Event.CHANGE, textChangeHandler);
addChild(myField);

function textChangeHandler(evt:Event) {
    var buffer:Number = 10;
    myField.width = Math.max(100, (myField.textWidth + buffer));
    myField.scrollH = 0;
}

Edit: Oh, and if you want that to work with .multiline, then just add:

myField.multiline = true;

and in the textChangeHandler function add:

myField.height = myField.textHeight + buffer;
Allan
  • 1,063
  • 10
  • 18