Calculating Text Width In ActionScript And Flex

前端 未结 8 2162
离开以前
离开以前 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 01:14

    So long as you're in a UIComponent, you can use the measureText function.

    public function howWideWouldThisTextBeIfItWereInThisButton(text:String,container:Button):int {
       var lineMetrics:TextLineMetrics = container.measureText(text);
       return lineMetrics.width;      
    }
    

    That being said, the flex button component should automatically size to the width of the text, if you don't set a width on it. That way if you need the text width, you can just call use the textWidth property.

提交回复
热议问题