Reputation: 865
I have a Text element in mxml. The text value is changing by user actions. I want to set the width to the exact size of the text. Since the width property is the actual component's width, I need the measuredWidth property after the FlexEvent.UPDATE_COMPLETE event is triggered:
textField.addEventListener(FlexEvent.UPDATE_COMPLETE, function(e:FlexEvent):void{
textField.width = textfield.measuredWidth;
});
This only changes to the proper width the first time. After that it only can be smaller but not larger. I've read the Text and the UIComponent source, and it said I need to call invalidateSize(). But it only works if I set the explicitWidth property NaN. So I made a setter function:
function setText(newValue:String):void {
textField.text = newValue;
textField.explicitWidth = NaN;
textField.invalidateSize();
}
But it's still only shrinking. My question is, how can I get always the proper measuredWidth value after the UPDATE_COMPLETE event?
Thanks
Upvotes: 0
Views: 462
Reputation: 2660
I agree with some of the commenters that there may be better alternatives that achieve the same result. However, you could use the measureText function of your Text element to determine the necessary width:
Upvotes: 0