Flex SDK mx:Text component word wrap bug fix

If you're having trouble getting word wrapping to work correctly in your mx:Text components when using minWidth and maxWidth, and setting width to a percentage (e.g., minWidth="0" maxWidth="300" width="100%"), it's not you, it's the Flex SDK (see bug 12826, reported by Tom Bray).

The fix, as provided by Mike Schiff, has been implemented in the SDK but until it is released you can extend mx:Text and implement it in your own projects:

  <mx:Script>
    <![CDATA[
      override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
        super.updateDisplayList(unscaledWidth, unscaledHeight);
        textField.wordWrap = textField.wordWrap || (Math.floor(measuredWidth) != Math.floor(width));
      }
    ]]>
  </mx:Script>

Comments