This example demonstrates the use of TextField.getRect() function.
package {
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.TextEvent;
import flash.geom.Rectangle;
import flash.text.AntiAliasType;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
[SWF( backgroundColor = '0x5B5B5B', frameRate = '33', width = '400', height = '200')]
public class TextFieldBackground extends Sprite {
private var format:TextFormat;
private var field:TextField;
private var background:Shape;
public function TextFieldBackground() {
background = new Shape();
background.x = 10;
background.y = 10;
this.addChild(background);
format = new TextFormat();
format.font = "Verdana";
format.color = 0x000000;
format.bold = true;
format.size = 12;
format.align = TextFormatAlign.LEFT;
field = new TextField();
field.autoSize = TextFieldAutoSize.LEFT;
field.antiAliasType = AntiAliasType.ADVANCED;
field.defaultTextFormat = format;
field.type = TextFieldType.INPUT;
field.multiline = true;
field.text = "Ichiban ni narukoto wa kesshite kantan dewanai.\nThe best never comes easy.";
field.x = background.x;
field.y = background.y;
field.addEventListener(TextEvent.TEXT_INPUT, onTextChange);
this.addChild(field);
drawBackground();
}
private function drawBackground():void {
var rect:Rectangle = field.getRect(this);
var gra:Graphics = background.graphics;
gra.clear();
gra.beginFill(0xFFFFFF);
gra.lineStyle(1, 0x000000);
gra.drawRoundRect(0, 0, rect.width, rect.height, 6, 6);
}
private function onTextChange(evt:TextEvent):void {
drawBackground();
}
}
}






















