Answered
dynamic resizing of text line
hi,
i want to create my own button with a label, so the button's width changes according to the label's size, up to a certain size (beyond it the text is cropped). since i'd like to support multilingual optionality at the future i've decided to use the textLayout framework instead of the simple textField class.
anyhow, i'm creating a textline like this (where 'cf' is a character format object):
TextLineFactory.createTextLinesFromString(callBack,"abcdefghijkl",new Rectangle(0,0,NaN,NaN),cf);
and then on the callback function -
private function callBack(textLine:TextLine):void
{
var w:Number = Math.min(textLine.width, 60); // let's say 60 is the button's maximum width
var h:Number = textLine.height;
var shape:Shape = ShapeDraw.drawSimpleRect(w + 4,h + 4); // my own method of creating simple black shapes
var sprite:Sprite = new Sprite();
sprite.addChild(shape);
shape.x = shape.y = -2;
sprite.addChild(textLine);
addChild(sprite);
}
how do i get to change the textLine's width after creation and have it cropped? or is there a way to pre-calculate the textline's width and have it set to that size?
cheers,
eRez
i want to create my own button with a label, so the button's width changes according to the label's size, up to a certain size (beyond it the text is cropped). since i'd like to support multilingual optionality at the future i've decided to use the textLayout framework instead of the simple textField class.
anyhow, i'm creating a textline like this (where 'cf' is a character format object):
TextLineFactory.createTextLinesFromString(callBack,"abcdefghijkl",new Rectangle(0,0,NaN,NaN),cf);
and then on the callback function -
private function callBack(textLine:TextLine):void
{
var w:Number = Math.min(textLine.width, 60); // let's say 60 is the button's maximum width
var h:Number = textLine.height;
var shape:Shape = ShapeDraw.drawSimpleRect(w + 4,h + 4); // my own method of creating simple black shapes
var sprite:Sprite = new Sprite();
sprite.addChild(shape);
shape.x = shape.y = -2;
sprite.addChild(textLine);
addChild(sprite);
}
how do i get to change the textLine's width after creation and have it cropped? or is there a way to pre-calculate the textline's width and have it set to that size?
cheers,
eRez
