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.
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.
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.
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.
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
my email is tufao@hotmail.com
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);
Thank You! Very Helpful (=
Thanks!! worked like a charm
wow cant believe I didnt find this before! Thanks