Here is code for a MultiLine Button. You put a line break (\n) where you want
it to break. I use it to get a vertical label by putting a line break between
each letter.
Hope this helps!
Warren
package myClassLibrary{
// from http://blogs.adobe.com/aharui/2007/04/multiline_buttons.html and
adapted slightly for Flex3
import mx.controls.Button;
import mx.core.UITextField;
import mx.core.IUITextField;
import flash.display.DisplayObject;
import flash.text.TextLineMetrics;
import mx.core.IFlexDisplayObject;
import mx.core.mx_internal;
use namespace mx_internal;
public class Button_MultiLine extends Button{
public function Button_MultiLine(){
super();
}
public function forceUpdate():void{
this.updateDisplayList(this.width,this.height);
}
override protected function createChildren():void{
if (!textField){
textField = IUITextField(createInFontContext(UITextField_NoTruncate));
textField.styleName = this;
addChild(DisplayObject(textField));
}
super.createChildren();
textField.wordWrap = true;
textField.multiline = true;
}
override protected function measure():void{
if (!isNaN(explicitWidth)){
var tempIcon:IFlexDisplayObject = getCurrentIcon();
var w:Number = explicitWidth;
if (tempIcon)
w -= tempIcon.width + getStyle(horizontalGap) + getStyle(paddingLeft) +
getStyle(paddingRight);
textField.width = w;
}
super.measure();
}
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;
}
}
}
import mx.core.UITextField;
internal class UITextField_NoTruncate extends UITextField
{
public function UITextField_NoTruncate()
{
super();
}
override public function truncateToFit(s:String = null):Boolean
{
return false;
}
}
- Original Message -
From: markflex2007
To: flexcoders@yahoogroups.com
Sent: Saturday, January 16, 2010 4:02 PM
Subject: [flexcoders] flex vertial button?
I try to vertical button like.but I can not see label in button.
mx:HBox width=100% rotation=90 x=100 y=100 clipContent=true
mx:Button id=myButton label=CLICK ME height=30 rotation=90 /
/mx:HBox
Do you have other ways.Thanks
Mark