Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adobe Flex: Word Wrap in Button Label

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!

like image 778
Mike Avatar asked Oct 31 '09 13:10

Mike


2 Answers

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.

like image 64
Christian Nunciato Avatar answered Nov 15 '22 10:11

Christian Nunciato


Trying using &#13;

I am using

<s:Button label="Top two&#13;states result" height="100%" width="100%" icon="@Embed(source='assets/bar.png')" chromeColor="#A3F4FD"/>

and it does multi-line label.

like image 45
Deepak Yadav Avatar answered Nov 15 '22 11:11

Deepak Yadav