Weirdness of the height property of TextField http://level0.kayac.com/2009/08/post_39.php 9re forked:3favorite:1lines:43license : MIT License modified : 2009-08-25 22:08:50 Embed Tweet package { import flash.display.Sprite; import flash.display.StageScaleMode; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; import flash.text.TextFormatAlign; // http://level0.kayac.com/2009/08/post_39.php public class TextFieldAutoSizeExample_0 extends Sprite { private const MAX_SIZE:int = 32; private const MIN_SIZE:int = 8; public function TextFieldAutoSizeExample_0() { var tf:TextField = new TextField(); var tfm:TextFormat = new TextFormat("_sans", 12, 0, null, null, null, null, null, TextFormatAlign.JUSTIFY); var i:int = MAX_SIZE; var str:String = "Flash Player Bug??\n\nFlash Player sometimes fails to get proper height of TextField. This may issue from internal text rendering process. You can avoid this problem by executing getter method - the height property is internally implemented as getter and setter method - before using the height property. If you comment out the line 39, the code fails to work properly."; stage.scaleMode = StageScaleMode.NO_SCALE; tf.autoSize = TextFieldAutoSize.LEFT; tf.wordWrap = true; tf.multiline = true; tf.text = str; tf.width = 300; tf.height = 1; addChild(tf); var tfHeight:int; while (i >= MIN_SIZE) { tfm.size = i--; tf.setTextFormat(tfm); // the follwing line avoids the problem tf.height; tfHeight = tf.height; if (tfHeight < 300) break; } tf = new TextField(); tf.width = 200; tf.text = "fontSize: " + i.toString() + " tf.height: " + tfHeight.toString(); tf.x = 310; addChild(tf); } } } Code Fullscreen Preview Fullscreen onedayitwill.. : thanks! TextField height TextFormatAlign.JUSTIFY TextFormatAlign.LEFT StageScaleMode.NO_SCALE toString text multiline String int sort new page view favorite forked pv205 forked from: Weirdness of the .. ekis forked:0 favorite:0lines:43 (diff:2) pv181 forked from: Weirdness of the .. sr_forest forked:0 favorite:0lines:43 (diff:1) pv142 forked from: Weirdness of the .. HYPERDASH forked:0 favorite:0lines:43 (diff:1)