What is Flex?

Posted: 16/04/09

An image of What is Flex?

After answering many questions relating to this issue on Flexdeveloper.eu, I've come to the conclusion that it would be a helpful, and a time-saving exercise, to write-down some of my descriptions of what Flex is (and isn't).

For many, Flex appears to be a different technology to Flash. THIS IS NOT TRUE. Flex is Flash. The output of a Flex project is a SWF that runs on the client in the Adobe Flash Player runtime.

Flex is a component framework that sits on top of the core Adobe Flash API. It allows the developer to use all of the basic ActionScript 3.0 features, as well as providing a vast library of visual and data components that allow the rapid development of Flash applications – all with a highly extendible OOP/component focus. Flex applications can be developed using ActionScript 3.0, or using Adobe's declarative mark-up language for Flex called MXML. When an application is written as MXML and compiled, the Flex Compiler parses the MXML and converts it to ActionScript inside a SWF container that the Flash runtime will be able to interpret. The Flash Player runtime does not interpret MXML code. If the application is written entirely with ActionScript, the compiler can skip the MXML-to-ActionScript conversion, and place the developer's code directly into the SWF (albeit for a few refinements and optimisations).

Flex applications can be developed using any text editing application (including notepad), although many developers prefer to use tools like Flex Builder, Eclipse and FDT, which provide extras like API code-hinting and integrated compiler code-checking, for increased developer productivity.

Flex cannot replace ‘n-tier' applications running on your web servers, that provide CRUD services. Flex, for example, is not a replacement for the Java code that retrieves a record from a database, when given an ID. Where Flex is able to fit in is over on the presentation layer of your system; so where before you had a HTML page displaying the results from the Java database query, you now have a SWF embedded in a web page; displaying the results in a prettier Flex component. The Flex application still needs the Java services running on the server, to act as the go-between. Normally, developers will ‘expose' their service as some kind of SOAP or REST web service, with a publicly accessible end-point, such as a JSP page or WCF .svc together with a WSDL description. When the Flex application requires data, it will asynchronously call the service end-point from the client (remember that Flash is a client-side technology), and display the response when it is returned. The Flex framework also had baked-in components that allow RPC invocation to remote gateways like BlazeDS and WebORB

When developers build MXML components for use in Flex applications, these components are essentially classes that are defined using declarative MXML mark-up instead of ActionScript. When they are compiled, they're converted to ActionScript classes, and become object definitions in the SWF that can be instantiated at runtime. An MXML document can't be resolved along a physical path, such as linking from one MXML document to another or loaded into a new window like some kind of HTML document. Remember, everything in your app compiles down into a SWF. Flex does not replace HTML pages like-for-like – you make a considered decision to change your user flow from a linear page-to-page navigation to one where a single application embedded in a web page can have multiple states, between which you can create transitions and rich interactions based on user gestures.

Used correctly, Flex has been proven to enable the rapid development of Flash applications using large development teams, and often consuming complex data through standard web service protocols.

Keywords for this post: flex, flex builder, mxml, fdt, flash, actionscript 3