Skip to main content

Pleasing Software: Flex 4 vs JavaFX 1.2: Dance Battle

I make it a point to follow Chet Hass on his Codedependent blog. He always has something interesting to say about features in Flex. Even though I rarely use Flex, he often demonstrates interesting animations or visual effects.

His latest post talks about the new transform effects in the upcoming Flex 4. Specifically he uses move (translate), rotate, and scale transforms to manipulate a control and make it twirl gracefully across the screen. Ok, that's a stretch, but I had to work the dance thing in here somewhere. You may want to watch his demonstration video now.

When I saw the MXML code that Chet was using for his demo, I was struck by how similar it is to the way I would accomplish the same thing in JavaFX. Below is Chet's Flex 4 demo code:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx=""

<s:Parallel id="transformer" target="{button}">
<s:Move xFrom="50" xTo="150" autoCenterTransform="true"/>
<s:Rotate angleFrom="0" angleTo="360" autoCenterTransform="true"/>
<s:Scale scaleXFrom="1" scaleXTo="2" autoCenterTransform="true"/>

<s:Button id="button" x="50" y="100" label="Transform Me"

And here is the same thing in JavaFX 1.2 formatted to emphasize the similarity:

import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.animation.transition.*;

var transformer:ParallelTransition;

def button = Button { layoutX: 50, layoutY: 100, text: "Transform Me"
action: function() { transformer.playFromStart() }

transformer = ParallelTransition {
node: button
content: [
RotateTransition { fromAngle: 0, toAngle: 360 }
TranslateTransition { fromX: 0, toX: 100 }
ScaleTransition { fromX: 1, toX: 2 }

Scene {
width: 400
height: 300
content: button

And here is the JavaFX application:

Some points of comparison:

  • MXML and XAML always lose me at xmlns. I'll take import statements any day, although most IDEs will manage XML namespaces and import statements for you. In general I simply prefer writing my declarative code in a programming language rather than a data interchange format - no matter how Flex-ible it is.
  • Deployment in a browser: Flex wins. Period. The deployment team at Sun has done a lot of work to narrow this particular gap, but Flash is still everywhere and it just works. I fully expect some significant number of people to have trouble running the applet above. And applets still flicker when the browser scrolls. Not serious, just annoying.
  • Flex has a slight edge in brevity, I think. But in return for some extra characters, you get all the benefits of static typing. The JavaFX compiler can catch syntax errors for you and IDEs will flag them immediately without having to run the program first. IDEs can also support much more robust refactoring and code completion (at least in theory, hopefully the Netbeans JavaFX plugin will finally get some more attention soon).
  • It seems odd that previous versions of Flex couldn't display text on a rotating control. And even these new transform effects have some gotchas to watch out for; like having to set autoCenterTransform on all the effects since they manipulate the same data under the covers. Not that JavaFX doesn't have some gotchas, but for the most part the foundation is solid. This kind of thing always surprises me when I hear about it. Flex is supposed to be way more mature, after all.

  • The JavaFX code above works on mobile devices (like the HTC Touch Diamond shown to the right) as well as on the desktop and in a browser. I'm just saying.

Twirling controls aside, you obviously can't make a definitive comparison of two competing technologies based on such a simple piece of sample code. I found it interesting how similar the code actually was between the two platforms. Hopefully you did too.

Posted via web from krzychukula's posterous


Popular posts from this blog

Course Review: The Bitfountain iOS 8 with Swift Immersive

This is second big iOS learning project. For first one read iOS Programming book review. As I only have two of them done I have to compare them somehow.

I am mindful that it took me a really long time to finish it (since last autumn). For a couple of months this year I didn't even have the internet to learn it, so it could not be helped. But last half of the June I've spent watching the videos every day and managed to finish it before any new internet problems.

So how was it?
In my opinion, it's great if you're starting out. There are a lot of basics, and seeing how to do things in XCode just makes your learning much easier than looking at the photos in the book. On the other hand, learning is more shallow and it is much easier to just follow the videos and learn only the basics without bigger picture about iOS SDK. I somehow missed more challenging exercises (even though I don't like to do them ;)

Course it pretty long but many videos are quite short (1-2…

How to Learn when Life is Short

I haven't really think this through but I have read really interesting articles recently and I just wanted to write for myself later.

Life is Short by Paul Graham

It's just that, learn from people older that you what is most important, and that life actually is short...

Instead of Goals or Resolutions, Try Creating Rules by Leo Babuta

In the time of New Year Resolutions, it's good to read something that is proposing different way of achieving things. Still I see much more value in habits than setting goals. But...

The Easy Way To Learn Hard Stuff by Per Harald Borgen
It's something that I read from time to time and I know it works sometimes for me. The things I learn then are really learned and something Jakub Wasilewski  has told me many times to do. Still it's uncomfortable and for some reason, I have failed to use this method more than once or twice. Writing it here so maybe I can think about it more and figure out how to do that more often.

Towards an understandin…

Hero's Journey in Presentations

Artur Skowroński recommended me: Want a Better Pitch? Watch This. by Andy Raskin and I think it is so great and applicable to all kinds of talks that I want to help it get more popular.
So the plan of presentation is going to follow these steps: Enemy - ProblemWhy now? - call to actionShow how the world will look like without the problemProblemsEvidence that you fixed the problem The image at the top is because it reminds me of Hero's Jurney. It has fewer steps but there is a lot of similarities. Especially #3 made me realize that grand vision of the future is something that I should have used in my talks.  The result at the start of the presentation makes a lot of sense actually. Everyone already knows that I speak about something because I probably fixed it and if you tell about it at the end then it might be hard for some people to see the bigger picture in the solution you're going to present.