Oct
13

HTML Links in Flex

By Joseph Labrecque  //  Flex  //  2 Comments

I’ve never found the need to have HTML links in Flex behave (and look) like their true HTML counterparts, but a student recently asked how she could get HTML links defined in a Text control to behave like regular HTML links.  After digging around, I found a lot of references to this problem but the solution turned up at Flex Freaks:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
 
import mx.core.mx_internal;
 
public function textHandler(e:Event):void
{
    var styleSheet:StyleSheet = new StyleSheet();
    styleSheet.setStyle("a:link", { textDecoration: "underline", color: "#30F" });
    e.currentTarget.mx_internal::styleSheet = styleSheet;
}
 
]]>
</mx:Script> 
 
 
<mx:Text initialize="this.textHandler(event)">
    <mx:htmlText>
    <![CDATA[
        You may <a href="">click</a> here.
    ]]>
    </mx:htmlText>
</mx:Text>
 
</mx:Application>

Apparently, this should not be used with any degree of reliability so far as future-proofing is concerned since the mx.core.mx_internal class may flux between versions of the Flex SDK.

Listed in the rumored Flex 4 improvements are support for CSS descendant selectors, ID selectors, and space-delimited style names. Something like this should really be handled via CSS so here’s hoping that this will soon be a much simpler process.

Not sure if I’ll ever need this in the future, but in the case that I do- I know it’s here for easy access.

2 Comments to “HTML Links in Flex”

Leave a comment

About this Website

This is the website of Joseph Labrecque: Senior Multimedia Application Developer for the University of Denver and Owner of Fractured Vision Media, LLC. Joseph is an Adobe Higher Education Leader.

Adobe Higher Education Leader

Adobe Certified

Aggregated by AXNA

Follow me on Twitter!