HTML Links in Flex
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.




I released a component a while back just for this purpose. You can find it at: http://agileui.blogspot.com/2008/06/styledtext-free-flex-component.html
in order for the HTML link to be properly executed, the ’selectable’ property of the containing TextField must be set to ‘true’
http://www.rockabit.com/2008/10/27/executing-html-links-in-flex/