Thursday, February 28, 2008

Multiline /newline Button label in Flex 3

I was having the hardest time getting a newline to appear in my Button component. I followed the documentation in the Adobe Flex 3 docs to use &13; but that still did not work.

I got some e-mails from Matt Horn of Adobe Flex Docs, and he gave me several things to try, including using the standard "\n" character escape sequence, and the HTML "<br/>". Finally, he gave me a link to a blog entry by Alex Harui titled "Multiline Buttons".

The code needed a little tweaking for Flex 3, but all I did was extend the Button class, and use the same exact code Alex used in his MultilineRadioButton.

That being said, here's my MultilineButton.
You can use this component like a regular button; the difference now is that if you include "&13;" in your label, it will render a newline!


import flash.display.DisplayObject;
import flash.text.TextLineMetrics;

import mx.controls.Button;
import mx.core.IFlexDisplayObject;
import mx.core.mx_internal;
use namespace mx_internal;

public class MultilineButton extends Button
public function MultilineButton()
//TODO: implement function

override protected function createChildren():void
if (!textField)
textField = new NoTruncationUITextField();
textField.styleName = this;
addChild(DisplayObject(textField)); //cast required for Flex 3; if in Flex 2; remove


textField.multiline = true;
textField.wordWrap = 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;


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;

Tuesday, February 26, 2008

Flex Day 2 (or 3, if you count Sunday)

The nightly parties at 360|Flex have been awesome, as well as the sessions.
Here's a review of some sessions I attended.

QTIndexSwapper and more Flash H.264 Fun - Renaun Erickson
  • Renaun showed his custom code which reindexes QuickTime movies so that the movie plays while downloading, AND the metadata is available sooner, rather than waiting for the entire movie to download
  • Check out his blog and link to his Google code:

Future of Flex - Deepa Subramaniam
  • Flex for Mobile
  • Thermo - RIA Design tool; easy for designers and developers to create revolutionary and interactive interfaces that can be taken directly into production
    • Feels like an Adobe Creative Suite product
  • MXML-G, a new graphics library
  • Flex 4 components - has a new MVC model, where the skin (defined via CSS) is considered the view
    • Deepa showed a demo where a button changed its look dynamically

Sunday, February 24, 2008

360 Flex Atlanta

I'm here in Atlanta for the 360 Flex Conference. It's a little cold here in ATL, but I'm in the comfort of the Omni Hotel, taking the Flex 101 course. We're building a photo application. I'll post more later!