James Ward: Sexier Software with Java and Flex

On Friday 11th July, I attended a talk by James Ward at Adobe’s Regents Park offices in London. Free beer, soft drinks and pizza were provided and this ensured that there was a fairly healthy turnout.

James started by showing two example Flex applications. The first was a demo to an insurance company to show how Flex could allow claim information to be entered more easily with the need for long textual descriptions replaced by annotated diagrams - for example detailing how the accident occurred involved dragging cars into position on an outline of the road, adjusting lines showing their trajectories and indicating where the collision occurred.

The second example application ran using AIR and appeared to the user like an ordinary desktop application. James showed how an interface chart in the application could be dragged into MS Word (where it became a static image) and similarly how tables could be dragged from the application and dropped into excel. Both applications looked very slick - I asked James later how long they had taken to build and he said about a couple of weeks.

James then moved to showing us how to build Flex applications. The Flex SDK is free to download and Flex applications can be build using only this and a text editor; however during the talk James used Adobe’s commercial FlexBuilder eclipse plugin.

A document written in MXML describes the application - James showed us variations on an application that would download photos from flickr tagged with "orange" and display them first using a widget like Apple’s "cover flow" and then as a simple list. The MXML code consisted of about 5 lines of which 2 were boilerplate and the rest served to define the data source, define the display widget, instruct the display to watch the data source for updates and start the search when the application was complely loaded.

The MXML for the examples were very similar for both the web and desktop versions but unfortunately not identical since different elements are used for the application top level tag. James did mention though that "library projects" could be created to contain code common to both the web and desktop versions of a Flex application and then separate web and desktop projects could reference the common code and contain only the code specific to their environment.

Individual components are written in Actionscript - this is very close to Javascript except that there seemed to be some proprietary extensions to, for example, indicate that variables can be used as data sources or sinks. James stated that statically defining types for variables was options but that adding types would tend to give better performance. Using static types also apparently allows FlexBuilder to provide code-completion and other useful features.

The combination of MXML and Actionscript components are compiled to a SWF file for web deployment meaning that Flex applications can run on a normal Flash runtime.

Web targetted Flex applications run in the browser and can make use of normal browser facilities (such as support for HTTPS connections). AIR applications run on the desktop - the AIR runtime includes Webkit to handle HTML rendering and also includes additional APIs to provide additional services such as access to the local filesystem.

James then moved on to some examples showing how a Flex user interface could be integrated with a Java backend. James stressed that Flex is a UI technology and so is not in competition with Java technologies used on the server side (Spring, EJB, hibernate etc). For this part of the talk James used an application that queried a Java servlet and displayed the results in a table using Flex. Flex supports a number of data transfer formats including JSON, XML and the binary AMF format. James showed how using AMF increased performance relative to using XML. If I understand it correctly AMF is a binary format close to the Flex/Flash in-memory representation of objects - this means that very little processing is required to handle a AMF data stream on the client side. James said that AMF performs better than XML since there is no need for serialisation and deserialisation - I felt this was somewhat misleading since obviously the Java backend will need to serialise the objects to AMF format even if deserialisation is not required on the client (since the objects can be presumably directly loaded into memory).

AMF is a proprietary Adobe protocol and was originally part of the commercial Lifecycle Data Services product. Adobe have now open sourced the code for AMF as the Blaze DS project.

Lifecycle Data Services remains a commercial product though and includes additional features such as the ability to keep multiple clients synchronised as a data source changes whether the data is changed by the server or by a client. James demonstrated three Flex applications running at once - one in a web browser, one embedded into a PDF document and the other running as a desktop application - each client displayed an editable table and updates to each table were propagated to the server and other clients without the application developer having to write code to handle this.

Although he did not describe it, James mentioned that there is an API for handling conflicts caused by multiple clients modifying the same data.

I felt James’s talk was an excellent introduction to Flex and some of the possibilities it provides. I hadn’t really considered using Flex before but now I definitely intend to give it try.

Some photos from the meetup can be found here.