How can I extend the LinkButton to allow HTML text in Flex?
I am loading the shortcut into my LinkButton directly from the string I get from the google API that puts in the html to format the label.
I want to extend linkbutton to allow this. I wrote a class myself to allow html text for the label and that aspect of it works, but now the background that appears on hover is too big. I tried to override measure () to fix this, but I didn't know how to do it. Here is the class I wrote:
package com.kranichs.components
{
import mx.controls.LinkButton;
public class HTMLLinkButton extends LinkButton
{
protected var _isHTML:Boolean;
public function HTMLLinkButton()
{
super();
}
[Bindable]
public function set isHTML(value:Boolean):void
{
_isHTML = value;
}
public function get isHTML():Boolean
{
return _isHTML;
}
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if(_isHTML)
{
textField.htmlText = label;
}
}
}
}
a source to share
measure () is the key.
Assuming you are using flex compatibility version> = 3.0, the key line is in Button.measure ():
var lineMetrics:TextLineMetrics = measureText(label);
You need to change this to something like:
var lineMetrics:TextLineMetrics = _isHTML ? measureHTMLText(label) : measureText(label);
You will probably need to copy the measurement function from the button to your class and make this change.
If you do this, what you most need to do is import the internal namespace, for example:
import mx.core.mx_internal;
use namespace mx_internal;
a source to share