ActionScript has very ****** support for determing the width/height of formatted text in a Flex component. I've wasted way too much time on this!
So I know this is real late, but hopefully if someone else has this problem and runs accross this they might find my solution helpful. This one way I used to solve this issue. I created the following function:
private function getTextWidth(target:Label):Number
var txtField:TextField = new TextField();
var txtFormat:TextFormat = new TextFormat();
txtFormat.font = target.getStyle("fontFamily");
txtFormat.size = target.getStyle("fontSize");
txtField.defaultTextFormat = txtFormat;
txtField.multiline = true;
txtField.wordWrap = true;
txtField.width = target.width;
txtField.text = label.text;
This looks like a good solution on paper, I'll have to try it out.
I managed to hack a temp solution for extending number of datagrid table rows
based on content in the data cell, but it was very kludgey and only worked for my specific font.
Will this return textHeight as well?
This problem cost me some time!