The Text control in Flex allows you to display non-editable, multi-line text with basic HTML markup.
But there’s a problem when it comes to anchor tags.
If you set the selectable property in the Text control to false, as I often do, the links in your HTML text will no longer work.
Believe it or not, this is by design!
From the Adobe® Flex® 3 Language Reference (emphasis added):
selectable property
selectable:Boolean [read-write]Specifies whether the text can be selected. Making the text selectable lets you copy text from the control.
When a link event is specified in the Label control, the selectable property must be set to true to execute the link event.
The default value is false;.
So it seems that if you want the links in your Text control to remain clickable, the HTML text must be selectable.
(Not the biggest deal of course, but it would have been nice to know before I spent an hour pouring over my code at 1am trying to figure out why my links weren’t working)

2 comments
Comments feed for this article
July 3, 2008 at 4:14 am
edeustace
Hi,
I’ve done a custom Text field that handles this.
basically i put a handler on the “click” event :
addEventListener( “click”, handleClick );
then heres the function:
private function handleClick( event : MouseEvent ) : void
{
var charIndex : int = textField.getCharIndexAtPoint( event.localX, event.localY );
if( charIndex == -1 )
{
return;
}
var textLength : Number = textField.text.length;
var format : TextFormat = textField.getTextFormat( charIndex, charIndex + 1 );
if( format.url != “” || format.url != null )
{
if( format.url.indexOf( “event” ) == 0 )
{
var textEvent : TextEvent = new TextEvent( TextEvent.LINK );
textEvent.text = format.url.substr( 6, format.url.length );
dispatchEvent( textEvent );
}
else
{
var request : URLRequest = new URLRequest( format.url );
navigateToURL( request, format.target );
}
}
July 7, 2008 at 10:43 am
Nick Schneble
That’s excellent!
I had to do something very similar in AIR beta 2 to force links to open in new AIR windows rather than new browser windows!