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?





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!
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.
@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.
I like that you think. Thank you for share very much.
Nice little piece of code. Very useful. Thanks a lot!
Your animated HTML link stole 1.6MB of my bandwidth and looking at the progress bar to load it was not a great user experience.
@fissiont bill me.
Stumbled upon your site when looking into using Flex for mobile application development. I used to be an ActionScripter, but moved on to other languages and frameworks. I was struck, while watching you code, how much repetition there was. Lots of similar code constructs, all following regular patterns and naming conventions, but still all that repetition… Have you looked at other dynamic languages and frameworks–specifically Ruby (and Rails)? I think you might like what you find.
Best wishes–and don’t be so down on HTML5 and web standards. It’s because of Flash that people can even dream of HTML5 and for the momentum of rich media web standards. Flash will always be a visionary part of the journey to whatever future web technologies and user experiences lay ahead.
Mark Coates recently posted..So many choices, so little time. Not that I’m complaining. Far from it, thankfully. I just…
@Mark I don’t really program much in anything other than Actionscript so I don’t notice the repetition.
I’m not really “down” on HTML5. I’m down on the idiots who think that HTML5 is the answer to everything. So I don’t mind picking at it. But I’m always pleased to see any advance in technologies and languages. I have no interest in using anything that requires coding specifically to a platform. If I consistently had to write AS code that worked one way on iOS and another way on Android I’d drop it like a hot potato. So obviously HTML is pretty much out the window for me. I did that for a decade. Never again – I hope. :-)