31 Jan 2009

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:Text xmlns:mx="http://www.adobe.com/2006/mxml">
	<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>
</mx:Text>

Add Your Comment

Spam Protection by WP-SpamFree

Flex SDK mx:Text component word wrap bug fix

  1. [...] > Aral Balkan – Flex SDK mx:Text component word wrap bug fix [...]

    localToGlobal » Blog Archive » news review -> 6th week of 2009
  2. Actually you do not have to extend the Flex component. Just do this in your code: textField.setStyle(“textField.wordWrap “,”textField.wordWrap”);
    Cheers
    /Niels

    Niels Bjerg
  3. Niels Bjerg, you rule

    Tyler Smith
  4. The topic is quite trendy in the net right now. What do you pay attention to when choosing what to write about?

    How to Get Six Pack Fast
  5. Thanks, but didn’t work for me.

    I had to change it like this;

    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
    {
    super.updateDisplayList(unscaledWidth, unscaledHeight);
    textField.height = unscaledHeight;
    }

    peter