“Be inspired, enjoy your work, keep learning and never forget to play.” — gskinner

Underlined link style in Flash

Posted: September 4th, 2007 | Author: tufao | Filed under: Actionscript2 | 9 Comments »

You want to have that tipical html effect when rolling over a text link showing text underlined? That is one of thouse things that is hard to understand how Marcromedia/Adobe didn't support this from the very beginning.

Sure you can have your text field as html and have your content defined by code with html tags and all, but do you really want to go through all that trouble. Shouldn't that be more simple just using static text?

I came up to a quite simple solution:

Basically styleSheet is created with the underline style which is applied for every object on a MovieClip. Check it out (AS2):

That's it! The underline effect on a link roll over is active for every static or dynamic text field on stage.


9 Comments on “Underlined link style in Flash”

  1. 1 Jason Woelfel said at 5:31 pm on May 16th, 2008:

    Can you tell me where this code goes? I have tried placing it in various places with no change. I know where ActionScripts go, but don’t know if I need to apply this code to a particular layer, frame, instance, etc.

    I have searched all morning for instructions on how to use CSS with Flash. I have not figured out a way to stylize static text that is hyperlinked. Your solution intrigued me, if only I can get it to work without manually drawing lines under the text.

    Thank you for any help you can give me.

  2. 2 tufao said at 9:22 am on May 18th, 2008:

    Is as simple as that. Just call styleHoverUnderline(movie), where “movie” is the parent containing all text fields.
    If you have further questions let me know.

  3. 3 n1cE said at 7:47 pm on July 13th, 2008:

    I just tried your example and I didn’t get it to work. I created a TextField and put it into an mc and named it “test_mc”. So i wrote styleHoverUnderline(test_mc);. And nothing happend. I think that your example can’t work because a lot of functions or whatever are not part of Flash. But when you can persuade me that it works I would be very very surprised. So please clear it up to me.

  4. 4 tufao said at 10:02 am on July 14th, 2008:

    Hi n1ce,

    This solution works fine. Just remember that you need to have an anchor defined on part or in the entire text (static or dynamic).
    If you need further help, just email me your fla and I take a look at it.

    cheers

  5. 5 tufao said at 10:04 am on July 14th, 2008:

    my email is tufao@hotmail.com

  6. 6 tufao said at 10:20 am on July 14th, 2008:

    Here is the solution in AS3:

    import flash.text.StyleSheet;
    import flash.text.TextField;

    function styleHoverUnderline(target_mc:MovieClip)
    {
    var styleObj:Object = new Object();
    styleObj.textDecoration = “underline”;

    var my_styleSheet:StyleSheet = new StyleSheet();
    my_styleSheet.setStyle(“a:hover”, styleObj);

    for (var i:int=0 ; i<target_mc.numChildren ; i++)
    {
    var obj:DisplayObject = target_mc.getChildAt(i);
    if (obj is TextField)
    TextField(obj).styleSheet = my_styleSheet;
    }
    }

    styleHoverUnderline(text_mc);

  7. 7 Dmitry M. said at 5:14 pm on January 16th, 2009:

    Thank You! Very Helpful (=

  8. 8 Tamara said at 1:52 pm on July 16th, 2009:

    Thanks!! worked like a charm :)

  9. 9 stu said at 4:13 pm on January 20th, 2010:

    wow cant believe I didnt find this before! Thanks


Leave a Reply