Archive for the ‘Flex’ Category

Foray into Flex AIR

November 3, 2009

Adobe AIR has really excited me since I’ve been a long time fan of desktop applications. There is a time and place for web apps as well as for desktops. This post describes some of my reflections on a partial port of a Swing application to Flex.

Globesight is an economic modeling package geared toward scenario playing with a complex visualization metaphor as well as some heavy-duty binary floating point storage. It was my  Swing/UI opus magnum that I crafted a few years back – lots of UI navigation, charting, plugins, XML and binary I/O crunching and transfers. Too bad I implemented this before I came across Spring!

Although I won’t have time to port the whole application from Java/Swing, I want to see how some of the key Java technologies are handled by Flex/AIR.

  • Binary file IO for floating point numbers – I have concerns regarding Flex’s performance
  • Charting – I used the versatile JFreeChart and I expect Flex will excel here
  • Multiple windows, dialog boxes, popups
  • General screen navigation
  • How well does the Java code and classes translate into ActionScript?


Globesight Swing


Globesight Flex


Initial Reaction

Designing the Main Workbench screen and populating it from the XML project definition files was easy enough. I can’t imagine doing that so quickly in Java! So far so good. Reading in the XML is a charm.

I’ve also been able to leverage the elaborate MVC Java class hierarchy representing the domain model and visual components into ActionScript. The package hierarchy and class names almost match one for one. This leads me to think, might a Java to ActionScript translator help here? I’ve already found some info on the topic. Too bad that I simply can’t reuse the Java classes directly from Flex – too bad Flex doesn’t use the  JVM. I guess I got spoiled using Groovy which can be seamlessly (and confusingly) mixed with Java.

I’m already running into major hiccups regarding binary IO. I’ve got two dimensional arrays stored in binary floating point format (and some longs and ints in the header), and I see that ActionScript doesn’t have a long or FP data datatype! There’s Number and byte array and ultimately I assume I’ll be able to read the data, but how efficiently?


Musings on Flex

October 20, 2009

I’ve recently been doing some hard-core Flex coding – refreshing some latent recent exposure and leveraging my other UI (namely Swing and Web) knowledge. Having just implemented several web services (REST and SOAP) for Flex/Flash front-ends, and having dabbled in some Flex, I decided to “bite the bullet” and implement an end-to-end Flex application. A particular emphasis was on exploring different Flex server-side technologies – HTTPService, WebService (SOAP) and BlazeDS options. I based the application on my existing canonical Playlist/Video web services application implemented with a SOAP (CXF JAX-WS) and REST (CXF JAX-RS) interface.The goal was to create a simple canonical CRUD application that could alernatively talk to different back-end providers, HTTP/REST, SOAP or LiveCycle/BlazeDS channels.

The first pass consisted in creating a tab panel of list views of the key domain objects – playlists, videos, genres, media and users. The goal was to have the data for each list view obtained from any number of back-end services. I started out with direct data provider binding, but soon moved over to an “adapter” middle layer model since each service was not guaranteed to send back the exact same format.

Having worked with a number of different technologies, I was curious to see how the Flex environment addresses some basic issues:

  • Distributed programming
  • Binary Protocols
  • UI programming
  • Declarative vs. Procedural
  • Type-safe programming
  • Frameworks

Sample Screens



Remote Programming

I’ve worked with many a distributed computing framework (RPC, CORBA, RMI, WS*, REST, HTTP/POX/*, etc.) over the last few years, and although as an insdustry we do seem to be making progress, its always surprising at how slow it is – sort of like two steps forward, one step backward. The Flex approach is especially unique in that it uses a dual declarative/procedural model – MXML and ActionScript. The former is great to get started, but as soon as you need to invoke rich services, the latter becomes move appealing.

For instance, I needed to talk to my existing REST service which I treat as a “whole” – all the different URIs comprise one service. The Flex HttpService seemed to be forcing me treat each URI as a separate “service”. No prob, I just created an AS component that wrapped this all up in one adapter service. 🙂 As usual, one starts out with a “simple” declarative approach but as soon as the beast of complexity rears its head, a procedural approach becomes more appropriate.

Binary Protocols

Yes to binary! XML is OK for some stuff, but any heavy duty system with performant SLA has to entertain binary. From the performance perspective, XML has been a big step backwards especially with its hyper-verbose begin-tag and end-tag duo. My question regarding the solution is: does Adobe have intentions to fully leverage the rich protocol capabilities and allow different client languages to bind to services? Any reason Java clients shouldn’t be able to consume AMF or RTMP? I haven’t researched this completely, but I’ve heard that AMF has recently been open-sourced.

Wild card question: what about GWT’s remoting protocol? How does it compare to AMF? Any reason that the two couldn’t be made more generalizable? I’m sure there are plenty of open source programmers more than willing to whip out language-specific client binding.

For more on the topic see:

UI Programming

I’ve got a lot to say on this after suffering through the hell of Swing GridBags. Flex layouts rock! But its not nirvana, and as soon as you want to fully control rendering, you’ve got to attend the gory details. C’est la vie, I suppose. Nice, nice integration with Eclipse – the Design and Source mode work without a hitch. More to be said later…

Type-safe programming

Although much of my recent experience has been with type-safe languages such as Java, the appeal of scripting languages is undeniable. Its not an “either-or” proposition – rather its the right tool for the right occasion. Unix scripting and lately Python have been a key components of my toolbox. AS is an interesting hybrid creature – it definitely has evolved more type-safe (less surprises at run-time) constructs than JavaScript, but there are still some apparent logical “inconsistencies” that need to be taken on faith. For example, what a hoops the underlying parser has to jump through to understand a binding of raw XML stanza to a variable without even quotes. I’d love to see the unit test for this! Cool! But…

Of more concern is the ability to “seamlessly” bind a “data provider” to a UI component such as a data grid. When the hoped-for happy path is executed all is fine, but when an unexpected data element is passed, Flex seems to silently swallow the error and displays nothing. The user then wonders: was there no data, or what? Perhaps I’m missing something here?

Furthermore, some of the error messages are positively impossible to figure out! For example, all of a sudden I started getting the following:

Error #2070: Security sandbox violation: caller cannot access Stage owned by

Not a hint, not a clue what the problem was. Thanks goodness to good ol’ Google, I was able to resolve the issue rather quickly (simply bad XML). But I really had hoped for more intelligence from the framework.

One of my “pet peeves” is making sure a system will report intelligible messages to the client when errors are encountered. Users expect that minimal politeness of the system: if the system know an error happened, please be so kind to tell us what it was! Of course, full “intelligence” can be surprisingly costly and complex. Of course, this a the topic for an a separate blog.


Having worked with Swing for quite a while, I know how hard it is to truly develop pluggable declarative components. Its not the technical aspect, its more the lack of a consistent approach in the Swing community. Lately there’s been movement in this space, but now that Swing has been officially deprecated by Sun (Oracle?), is this all moot?

This is where Flex definitely shines. The ability to mix D & P – declarative/MXML and procedural/AS is truly cool. Reuse is predicated on being able to modularize common functionality – be it Flex components or OSGI modules. Of course “the devil is in the details” – the right mix of D or P in a component has to be decided on a case-by-case basis. Ill definitely be spending more time delving into this topic.

Declarative vs. Procedural and Frameworks

At first, the dissonance between “angly” MXML and “curly” AS is a bit jarring, but I suppose one gets used to it. Two different ways to do the same thing. With so many choices, comes responsibility. I’m looking forward to exploring some of the up and coming Flex frameworks such as Cairngorn, Spring ActionScript, Swiz, Mate, etc. to see how they can streamline the effort.

For more, see Christophe Coenraets’ articles: