Helping Adobe Flex community in developing Rich Internet Applications (RIA) in MXML, Actionscript and Flash.

<mx:Label text="Crazy about Flex"/>

You are not logged in.

  • Index
  •  » FAQ & Tutorials
  •  » I just want a link that behaves like HTML hyperlink (underline on mouseover). How do you do that?

#1 Aug 29th 2007 4:46 PM

pixelfreak
Crazy Flexer
Registered: Aug 28th 2007
Posts: 61

I just want a link that behaves like HTML hyperlink (underline on mouseover). How do you do that?

Doable, although not as trivial. You can do this by setting a stylesheet containing the pseudo class you usually use in regular CSS to customize a hyperlink. And when I say stylesheet, I mean flash.text.Stylesheet that will affect the HTML DOM, NOT Flex Styles which affects Flex DOM. Here's a sample:

Code:

import mx.core.mx_internal;

public function textHandler(e:Event):void
{
    var styleSheet:StyleSheet = new StyleSheet();
    styleSheet.setStyle("a:link", { textDecoration: "none", color: "#813F98" });
    styleSheet.setStyle("a:hover", { textDecoration: "underline" });
    styleSheet.setStyle("a:active", { textDecoration: "underline" });
    e.currentTarget.mx_internal::styleSheet = styleSheet;
}

<mx:Text initialize="this.textHandler(event)">
    <mx:htmlText>
    <![CDATA[
        <a href="#">Click!</a>
    ]]>
    </mx:htmlText>
</mx:Text>

A word of caution: Adobe uses the mx_internal namespace to mark things that may change in future versions of the framework. So use this at your own risk, your code may not work with future releases of Flex.

Another less elegant alternative is to add rollover and rollout listeners to the label/text, parse its htmlText and add <u></u> to it.

Why is it so ridiculously hard to do something so simple? Here's a comment from Gordon Smith, a Flex developer at Adobe.

Gordon Smith wrote:

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.

Offline

 

#2 Apr 20th 2008 3:19 AM

shapeshifta
Flex Apprentice
Registered: Apr 19th 2008
Posts: 34

Re: I just want a link that behaves like HTML hyperlink (underline on mouseover). How do you do that?

Very cool, could not find that anywhere!
Thanx, will try next time.

Offline

 
  • Index
  •  » FAQ & Tutorials
  •  » I just want a link that behaves like HTML hyperlink (underline on mouseover). How do you do that?

Board footer

Powered by PunBB