It's possible, but not trivial, to style hyperlinks in HTML text in
Flex. Here is an example:

 

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="vertical">

            <mx:Script>

                        <![CDATA[

                                    import mx.core.mx_internal;

                                    private function
label1_initializeHandler(event:Event):void

                                    {

                                                label1.htmlText = "Click
<a href='http://www.adobe.com'>here</a>";

 


                                                var
styleSheet:StyleSheet = new StyleSheet();

 
styleSheet.setStyle("a:link", { textDecoration: "underline", color:
"#0000FF" });

 
styleSheet.setStyle("a:hover", { textDecoration: "underline", color:
"#FFFF00" });

 
styleSheet.setStyle("a:active", { textDecoration: "underline", color:
"#FF0000" });

 
label1.mx_internal::styleSheet = styleSheet;

                                    }

                        ]]>

            </mx:Script>

            <mx:Label id="label1" selectable="true"
initialize="label1_initializeHandler(event)"/>

</mx:Application>

 

You must do it through the Flash Player's StyleSheet class; you can't
use <mx:Styles>. Flex's CSS styles apply to the Flex DOM, while
StyleSheet applies to the HTML DOM.

 

We haven't devoted a lot of attention to HTML text in Flex because the
Flash Player's support for HTML is so limited and many Flex developers
find it doesn't meet their needs, Apollo will change that, but it isn't
clear when the Player's HTML support for Flex apps in the browser will
get better.

 

- Gordon

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Ethan Miller
Sent: Thursday, November 30, 2006 1:33 PM
To: [email protected]
Subject: Re: [flexcoders] Re: Styling in Flex is officially ridiculous

 

While in general I've been fairly happy with my ability to style 
flex, one area in which really lacking (and unfortunately for me in a 
key place for my application) is in styling text, especially text 
contained in an htmlText element.

Despite reading the docs 5 times now, I remain unable to style a 
simple anchor tag (<A HREF="">. "A" as a type selector doesn't work, 
but neither do a:link, a:hover, or a:active which the docs say should 
work. Why the A tag doesn't simply support styleName as an attribute 
(or class="" or style="") is a complete mind bender to me. Why 
htmlText doesn't support <span styleName=""> is equally puzzling.

Also, is it just me or are many of the css property names different, 
eg font-family vs fontFamily, etc. And what about shorthand syntax, 
eg "border: 1x dotted black."

I realize and accept as necessary and good the need to support a 
limited set of HTML tags but don't understand why standard and 
rigorous text styling is so out of reach. This in fact would be one 
of my top wish list items for future releases.

Meantime, if anyone has any tips on styling text now, I'm all ears =)

cheers, ethan

 

Reply via email to