Styling HTML Text Links in Flex
However the bug only exists for pre-written CSS files - if you create a CSS object dynamically and attach it to the text control, the link styles work.
So to style an mx:Text control's links, you can use the code below to rewrite your CSS on the fly. The code looks in your CSS file for the style to apply to links, and from it creates a new CSS stylesheet to apply to the text control.
The hex value returned by toString(16) lacks leading zeros, but the CSS parser for dynamically created CSS does not require them like it does for pre-written CSS files, so it works fine.

function attachLinkStyleToText(textControl:Text)
{
// find the CSS class containing the formatting you want to apply to links in the text
var linkColorClass:CSSStyleDeclaration = StyleManager.getStyleDeclaration(".yourHTMLLinkClassName");
if (!linkColorClass) return;
// find the style you wish to apply, in this case just the color
var linkColor:Number = parseInt(linkColorClass.getStyle("color"));
if (!linkColor) return;
var linkColorHex:String = linkColor.toString(16);
// create a new CSS style sheet that applies this style
var linkCSSText:String = "a {color:#"+linkColorHex+"}";
var linkCSS:StyleSheet = new StyleSheet();
linkCSS.parseCSS(linkCSSText);
// attach the new CSS to the text control
textControl.styleSheet = linkCSS;
}
Spread The Word
4 Responses to "Styling HTML Text Links in Flex" 
|
said this on 18 Apr 2010 1:07:54 AM CDT
Very interested, I search
|
|
said this on 05 Jul 2010 12:48:13 PM CDT
Thanks a lot!! This would
|
|
said this on 08 Sep 2010 10:19:55 AM CDT
The mx:Text component doe
|
|
said this on 08 Sep 2010 3:05:08 PM CDT
Sorry Haik! We are still
|
Author/Admin)