Subscribe to RSS
get email updates
home | about | pixDif AIR app | video tutorials
polyGeek.com

Register for 360Flex in DC using the ad below and you will automatically be entered in a drawing for a free ticket. Read more.
place your ad here

Web Premium





Make that Flex Button look like an HTML link

February 21st, 2010 . by polygeek

Sometimes it’s the simple things that make us happy. And for me one of those simple things is just how easy it is to make a <s:Button> look like an HTML link with Flex 4.

view source

If you’re an HTML coder then first, “WTF you doin’ on my blog hillbilly boy?” and second you’re probably thinking, “Yeah, or you could just use HTML in the first place and actually have regular links. That may be true but can your regular links do this?

view source

I’m laughing at the superior web standard. ( from??? ) And if you can do that with your shitty Javascript then can you do it in just 5 minutes – on all browsers? ‘Cause that’s all it took me and I’m being generous.

Watch the music-video tutorial

Show me some skin
Here’s all that you need in your HTMLBtn skin file. I said it was easy. Was I right or was I right? :)

<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo">

<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/halo";

	.upStyle { color: #0000FF; }
	.overStyle { color: #009900; }
	.downStyle { color: #00FF00; }
	.disabledStyle { color: #666666; }

</fx:Style>

<s:states>
	<s:State name="up" />
	<s:State name="over" />
	<s:State name="down" />
	<s:State name="disabled" />
</s:states>

<s:transitions>
	<s:Transition toState="over" autoReverse="true">
		<s:Resize target="{ underlineOver }" />
	</s:Transition>

	<s:Transition toState="up" autoReverse="true">
		<s:Resize target="{ underlineOver }" />
	</s:Transition>
</s:transitions>

<s:Label
	id="labelDisplay"
	styleName.up="upStyle"
	styleName.over="overStyle"
	styleName.down="downStyle"
	styleName.disabled="disabledStyle"/>

<!--This is the blue line that is always present-->
<s:Rect
	width="100%" height="1"
	bottom="0" horizontalCenter="0">
	<s:fill>
		<s:SolidColor color="#0000FF"/>
	</s:fill>
</s:Rect>

<!--This is the green underline that grows out to 100%
width when the mouse moves over and then shrinks
back to 0 width when the mouse moves out.-->
<s:Rect id="underlineOver"
	width.over="100%" width.up="0" height="1"
	bottom="0" horizontalCenter="0">
	<s:fill>
		<s:SolidColor color="#009900"/>
	</s:fill>
</s:Rect>

</s:Skin>

Notice that the <Resize> Transitions only specify a target. You don’t have to bother with telling it exactly what width to transition to. It figures that out from the properties of the target. In this case it’s the <Rect> which has width.up=”0″ and width.over=”100%”. Have I said lately that I love Flex 4 states?

If something here has proved valuable to you then feel free to drop a couple of bucks in the tip-jar.

Post to Twitter Post to Delicious Post to Facebook Post to Reddit Post to StumbleUpon


similar posts

5 Responses to “Make that Flex Button look like an HTML link”


comment number 1 by: John

The code you provided is working really well, I like it very much, thanks for sharing it with is, I like the way you present the whole details along with a step by step coding!

comment number 2 by: JabbyPanda

Cool stuff, let's forget about styling of mx:LinkButton from Flex 3 and move on to new Spark Button instead.

A few remarks although.

First, why do you use s:Rect graphic primitive, not s:Line primitive?

Second, while the color animation of the line looks cool, the line is drawn with more visible offset from the text itself when compared to applying "textDecoration='underline' style to s:Label, I would change its bottom position from 0 to 1px.

And view source links are currently broken.

comment number 3 by: KINGRPG

I like that you think. Thank you for share very much.

comment number 4 by: polygeek

@JabbyPanda, Thanks for letting me know the source code links were broken. That’s always a problem. I accidentally overwrote them at some point and broke it. Not the first time that’s happened.

Yes, I should probably use a s:Line. I use s:Rect so often that it’s just habit. Good observation about the line placement. I’ll make sure I change that in my apps where I’m using it.

comment number 5 by: Matthew

Nice little piece of code. Very useful. Thanks a lot!

   Welcome back (Change)

Leave a Reply

comment feed RSS   subscribe to this comment thread

Recent Posts

   



polyGeek.com

© Copyright 2008 polyGeek.com / Dan Florio, All Rights Reserved Except Where Explicitly Stated
Web Developement Blogs - Blog Catalog Blog Directory
M2 Websites
Local Directory for Los Angeles, CA

Better Tag Cloud