Musings on Flex

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:

One Response to “Musings on Flex”

  1. Lightweight WS/SOA Infrastructure « Andre's Tech Blog Says:

    […] Andre's Tech Blog Tech and Life « Musings on Flex […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: