Q:

creating dynamic rectangle

Hello i'm wondering how i can create a dynamic rectangle wich has some text in it, the text is dynamic so the rectangle has to adapt to the length of the text. Any ideas on how to approach this?

A:

here is a basic one for single line text:
import flash.display.Sprite;
import flash.text.TextField;

var rectClip:Sprite = new Sprite();

var rect:Sprite = new Sprite;
rect.graphics.beginFill(0xff0000, 1);
rect.graphics.drawRect(0, 0, 100, 100);
rect.graphics.endFill();

var tf:TextField = new TextField();
tf.autoSize = "left";
tf.text = "Lorem ipsum dolor sit amet...";

addChild(rectClip);
rectClip.addChild(rect);
rectClip.addChild(tf);

rect.width = tf.textWidth + 12;
rect.height = tf.textHeight + 12;
tf.x = Math.round(rect.width/2 - tf.width/2);
tf.y = Math.round(rect.height/2 - tf.height/2);

Rob

