Calculating Text Width In ActionScript And Flex

前端 未结 8 2159
离开以前
离开以前 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:53

    as I think, textField.textWidth construction works fine... until you change the font size. It seems it calculates width based on 12px font. So, if you have embedded font and global styling you can try fast solution:

    var realWidth = myLabel.textField.textWidth * (fontSize / 12);
    

    I've tried this on long and short strings and the result is correct.

提交回复
热议问题