Adobe Flex 3 LinkButton Word Wrap

I recently ran across an issue that required a Flex LinkButton control to wrap its contents due to design constraints. If it didn’t wrap, it the LinkButton would blow the design once the page rendered.

If you ever happen to need a LinkButton with word wrap, here is a tiny component that should serve you well.

This is how you use it. First, in your MXML file, define a namespace for your custom components:

1
2
3
4
< ?xml version="1.0" encoding="utf-8"?>
<mx :Panel width="20%" height="100%" 
	xmlns:mx="http://www.adobe.com/2006/mxml" 
	xmlns:utils="comp.utils.*"

Then call the custom component later on in that file where you need it:

1
<utils :multiLineLinkButton id="yourLinkID" width="100%" label="Your Wrapping LinkButton" styleName="whiteText" buttonDown="navigateToURL(new URLRequest('YOUR URL'),'_self');"/>

Then copy the code below into a text file named “multiLineLinkButton.as” and place it into the “comp\utils” directory of your file structure.

?View Code ACTIONSCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package comp.utils {
	import mx.controls.LinkButton;
	import flash.text.TextLineMetrics;
 
	public class multiLineLinkButton extends LinkButton {
		override protected function createChildren():void {
			super.createChildren();
			if (textField){
				textField.wordWrap = true;
				textField.multiline = true;
			}
		}
 
		override public function measureText(s:String):TextLineMetrics {
			textField.text = s;
			var lineMetrics:TextLineMetrics = textField.getLineMetrics(0);
			lineMetrics.width = textField.textWidth;
			lineMetrics.height = textField.textHeight;
 
			return lineMetrics;
		}
	}
}

Bookmark and Share

2 comments to Adobe Flex 3 LinkButton Word Wrap

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Get Adobe Flash playerPlugin by wpburn.com wordpress themes