The standard Flex button does not allow the Label Text to word wrap. I read in the internet that there are some undocumented ways to handle this but I did not get them to work. If somebody could post me a small example would be great!
+2
A:
Essentially you need to set a few protected properties on the Button's TextField control (multiLine and wordWrap), which you can't do without extending the Button class. So if you create a new class that extends Button and sets those properties and does a little work to make things measure out correctly:
package
{
import flash.text.TextFieldAutoSize;
import mx.controls.Button;
public class WrappingButton extends Button
{
public function WrappingButton()
{
super();
}
override protected function createChildren():void
{
super.createChildren();
textField.multiline = true;
textField.wordWrap = true;
textField.autoSize = TextFieldAutoSize.CENTER;
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
textField.y = (this.height - textField.height) >> 1;
height = textField.height + getStyle("paddingTop") + getStyle("paddingBottom");
}
}
}
... you can drop that control into your MXML like so:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">
<local:WrappingButton label="The quick brown fox jumped over the lazy dog." width="100" paddingTop="10" paddingBottom="10" />
</mx:Application>
Hope it helps! Post back with questions if you have 'em.
Christian Nunciato
2009-10-31 17:04:01
Great component, but I'm attempting to use it as a custom item renderer, and updateDisplayList() is called in an infinite loop.
Laramie
2010-10-22 21:04:28
A:
thanks for the wonderful component. my question is this, when i apply icons to the button, say a 30x30 icon, the button gets messed up. how do i set it up so the button could accommodate the image.
user
2010-01-21 04:59:59
this should not be in the answer selection. Please comment on areas you have questions about or create a question.
asawilliams
2010-08-10 21:02:20
this should not be in the answer selection. Please comment in areas you want to give thanks, and up vote.
asawilliams
2010-08-10 21:03:23
A:
can you give the complete answer,,,, means how this thing works completely. since i'm new in flex
ankit gupta
2010-05-18 10:03:04
this should not be in the answer selection. Please comment on areas you have questions about or create a question
asawilliams
2010-08-10 21:02:36