28 December 2012

Adobe Flex & ActionScript Crash Course

This article will try to provide a lightning quick introduction to the Flex and ActionScript technologies. Although supposedly a dying technology, Flex does have it's somewhat large user base and perhaps, now that it is donated to the Apache Foundation, it my be resurrected. And since I am a Java evangelist, I would present this from a Java perspective. Of course, as you might have guessed, most of what I mention is also available for other server-side frameworks and languages, so the principles are the same.

First of all - what is FLEX?
Flex is, basically, a (mostly) client-side technology for building RIA applications. It's usage is free of charge, however the FlexBuilder (IDE used to help develop Flex applications) is not.
Since Flex runs inside the Adobe Flash runtime platform independance is handled by Adobe (in contrast to technologies such as JavaScript or HTML5 which are standartized and handled by the browsers themselves without the need of plugins). As such this approach has the advantage of Adobe making sure that content is visualized in the same way no matter what the browser is. This, of course, comes with the disadvantage of Adobe having to support all the platforms themselves.
In short Flex allows the creation of MXML files defining page structure (panels, forms with buttons, lists, etc.) and converting this into a SWF file, which could later on be used by the Flash runtime to display the content of the page in a browser (or somewhere else).

So where does ActionScript fit in?
In reality ActionScript is just another implementation of the ECMAScript standard (similarly to JavaScript). From an architectural perspective the ActionScript is used to write the Model and the Controller when writing an application using the MVC pattern while the MXML is used to describe the view. In other words ActionScript defines the behaviour of the visual components and the data model supplying each of them.
If you have never ever used JavaScript or any ECMAScript-like language, but you are familiar with Java you can take a quick look at this article.

Where does Java fit in this picture?
Remember how I mentioned that Flex is mostly client-side? This is because in practise we rarely create a web application that needs to be run entirely on the client because, obviously, this would defeat the purpose of having a server.
Typically we would want only a small part of the controller code to be executed on the client (for example, if we take JSF for example, we would want the validation phase, the binding phase, the converting phase and etc.) while other parts (such as database operations or heavy calculations) would still take place on the server in our (probably) stateless beans that contain the business logic.
No matter what the actual server implementation is, Flex provides a remoting mechanism called BlazeDS which handles the communication between controllers and views and the Java back end (essentially providing serialization, de-serialization and method invocation on the server and client). Adobe provides a good article on this topic that explains just how this works.

What else is there about Flex that I'd like to know?
There is a lot, actually. A quick (and incomplete) list would be: