Multiline Button

Flex Add comments

Pretty straightforward. If is a multiline button what you need, then a multiline button is what you have!

Check also: http://flexrays.wordpress.com/2007/04/24/multilined-label-for-a-button/ and http: blogs.adobe.com/aharui/2007/04/multiline_buttons.html
Both are great references.

MultilineButton .as 

[code lang="actionscript"] package com.multilineButton{import flash.text.TextField;
import mx.controls.Button;
import flash.text.TextLineMetrics;

//check also: http://flexrays.wordpress.com/2007/04/24/multilined-label-for-a-button/
//and also: http://blogs.adobe.com/aharui/2007/04/multiline_buttons.html
//great stuff!!

public class MultilineButton extends Button    {

//private var _textField:UITextField;

public function MultilineButton(){
super();
}

override protected function createChildren():void{
if (!textField){
textField = new NoTruncationUITextField();
textField.styleName = this;
addChild(TextField(textField));
}

super.createChildren();

textField.multiline = true;
textField.wordWrap = true;
}

override public function measureText(s:String):TextLineMetrics{
textField.text = s;
var lineMetrics:TextLineMetrics = textField.getLineMetrics(0);
lineMetrics.width = textField.textWidth + 4;
lineMetrics.height = textField.textHeight + 4;
return lineMetrics;
}
}
}[/code]

NoTruncationUITextField.as

[code lang="actionscript"]package com.multilineButton{

import mx.core.UITextField;

public class NoTruncationUITextField extends UITextField{

public function NoTruncationUITextField(){

super();
}

override public function truncateToFit(s:String = null):Boolean{
return false;
}
}
}[/code]

5 Responses to “Multiline Button”

  1. Billy Says:

    Hi Gabriela,

    I am new to Flex and I’ve got a newbie question. How do I reference the package within a component? I know for a fact I can’t nest it as into a block.
    Thanks for your help.

  2. gabrielaperry Says:

    Hi.
    Im not sure which pakage youre talking about, but this ii is not that important at all (only woukd make the example more concrete).
    Lets say your thinking of using this multiline button.
    You should hava a folder named “com” and another one (inside it) named “multilineButton”. This class should be inside this last folder.

  3. Umer Says:

    this is not a problem now

    http://flexlib.googlecode.com/svn/trunk/docs/flexlib/controls/CanvasButton.html

    Very simple

  4. mdintl08 Says:

    Thanks for the post, I have been having the same problems.

  5. Oralee Bousquet Says:

    your submit is damn intriguing to read!

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in