Calculating Text Width In ActionScript And Flex

前端 未结 8 2160
离开以前
离开以前 2020-12-30 00:47

I\'m trying to calculate how WIDE to make my button, based on the text that it will contain, and when I try to google for how to calcuate something as simplistic as the WIDT

8条回答
  •  清酒与你
    2020-12-30 00:56

    This works any format, size, font type. Don't forget properties "autoSize" and "wordWrap"!

    var tf:TextField = new TextField();
    addChild(tf);
    tf.autoSize = TextFieldAutoSize.LEFT;
    tf.wordWrap = false;
    tf.text = "Whatever here";
    tf.width = tf.textWidth + 4; // add 2 pixels-gutters left & right
    

    Your button will need to be "tf.width" wide...

提交回复
热议问题