You need to use a "fixed" width for the text field rather than autosize
and you can also use the textWidth / textHeight on TextField. Maybe if
you set the width to a maximum first, add your text, then if the text is
too long, "square" your text field off a little. I am sorry, text
metrics may have been a bit of a red-herring. In AS2, you could ask for
the size of a string of text using TextFormat.getTextExtent which
returned the same type of TextMetrics object. It's a little different
in AS3, so I think you have to fix the width first, then adjust after
you read the other values back.
Sorry & Hope this is a bit more helpful.
Glen
Alexander Farber wrote:
Hello Glen,
On Fri, Oct 9, 2009 at 2:51 PM, Glen Pike <g...@engineeredarts.co.uk> wrote:
You can get the text metrics - |flash.text.TextField.getLineMetrics()|
Have a look in the docs about this class it's quite useful. Watch out for
the obligatory 2px gutter around your text..
Alexander Farber wrote:
(my code available at http://pastebin.com/m6d9f4087 )
thank you, I've changed my code to:
public function set text(str:String):void {
_tf.x = PADDING + Util.randRange(10, 40);
_tf.y = PADDING + Util.randRange(10, 40);
_tf.width = W;
_tf.text = str;
if (1 == _tf.numLines) {
var metrics:TextLineMetrics =
_tf.getLineMetrics(0);
// add TextField gutter on both side
_tf.width = metrics.width + 2 * 2;
}
......
}
But that 2 * 2 seems to be not enough,
because the TextField breaks my line in two
after I set its width to metrics.width + 2 * 2.
There are probably additional margins
at left and right sides?
Regards
Alex
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders