22 March 2010
This article provides an overview of the technologies behind building Flex and Java applications. Depending upon your background as a Java, Flex, Adobe AIR, or other developer, you may be familiar with some but not all of these technologies.
The Adobe Flash Platform is what Adobe calls its entire family of technologies used to create, run, and provide data to rich applications (in the form of SWF files), including client runtimes, tools, frameworks, servers, and cloud services. Many of its individual components are discussed in detail in this article.
At the center of the Flash Platform are the client runtimes: Adobe Flash Player for the browser and Adobe AIR for outside the browser. The runtimes render applications created on the Flash Platform (in the form of SWF files).
Adobe Flash Player is a browser plugin or Active X control that has a much richer object model and rendering engine that allows developers to include more highly expressive and interactive content in web applications. To include this richer content, you create you a SWF file (a compiled bytecode file which is what Flash Player can render) using some developer tool and then reference this SWF file in your HTML page. When the HTML page is parsed by the browser, the SWF file is downloaded and run by Flash Player in the browser window.
Flash Player is the client runtime for applications created on the Flash Platform in the browser. These applications have all the benefits of browser-based applications, including anywhere access, easy deployment (no installation necessary), simple updating, and consistency across all operating systems and browsers. They also have all the limitations of browser-based applications, including no offline access and the confines of the browser's security sandbox which keeps them from interacting with the user's computer outside the browser window.
In order to get the best of both worlds, Adobe introduced Adobe AIR, a cross-operating system runtime and set of tools that enable developers to deploy HTML, Ajax, and Flash Platform applications (SWF files) to the desktop. An emerging design pattern for applications is to deliver a browser-based version for all users and a desktop version for more active or power users. You can use tools such as Flash Builder and Flash Professional to create SWF files for both web and desktop applications. If you create both types of applications, you can also share code from separate code libraries.
You can use Flash Builder to create both web and desktop applications with Flex. If you create both types of applications, you can also share code from separate code libraries. When you compile a Flex application for the desktop you get a SWF file and an XML file (called the application descriptor file) which includes information about what the container operating system window should look like, what icon should be used for the application on the client computer, and more.
During development, it would be inconvenient (to say the least) if you had to install the application on your computer every time you wanted to test it. Instead when you test an application, Flash Builder launches a tool called the AIR Debug Launcher (ADL), which allows you to run the application without installation. When you are ready to deploy, Flash Builder uses a tool called the ADT (AIR Development Tool) to create a release build consisting of an AIR package file, which includes the SWF file, the application descriptor file, assets, and more. The AIR file is the one you must distribute to your users. When you export, you must also associate a digital certificate from a trusted agency to sign the application since it will install on the user's computer with full permissions and have capabilities for interacting with their operating system. (Of course, you should only ever install trusted applications to minimize the chance they may contain any harmful code.)
In order to install an AIR application, users must have the Adobe AIR runtime installed. To provide a more seamless install experience for the user so they can install the application from a web page (instead of having to to download and install the AIR runtime and then download and install the AIR application), Adobe provides a default HTML file and badge.swf file which provides a template for letting users click a badge (a framed, customized image button) that checks and installs the runtime if necessary and then installs the AIR application. If you go the Adobe AIR Marketplace, you will see this is how all the applications are delivered.
Adobe creates many tools for creating SWF files, including Flash Professional, Flash Builder (formerly Flex Builder), Flash Catalyst, and more. Each tool caters to different developer and designer skill sets.
Adobe Flash Builder is an Eclipse-based development tool targeted at developers. With this IDE, you use the Flex framework to create SWF files. Flash Builder accelerates Flex application development by providing intelligent code hinting and generation, refactoring, compile-time error checking, interactive step-through debugging, and visual design for laying out and styling user interfaces.
In addition to developing tools for creating applications, Adobe also created frameworks to help developers more quickly and easily build robust applications rich in functionality.
Adobe Flex is a free, open source framework comprised of a library of ActionScript classes (ActionScript is the scripting language for the Flash Player) and executables to help you more quickly and easily develop, compile, and interactively debug applications. The Flex framework includes classes for over 100 extensible components, including UI controls (buttons, list boxes, sliders, steppers, data grids, charts, and more), containers (VGroup, HGroup, Panel, Form and more to help you build adaptive application interfaces), managers (for styles, drag and drop, focus, popups, cursors, browser history and deep links, and more), remote procedure calls (HTTP request, web services, and remote objects), formatters, validators, and utilities. Use the Tour de Flex application to explore the Flex framework and see the various components in action.
You create Flex applications (SWF files built with Flex) using two languages: ActionScript and MXML. ActionScript is an inheritance-based object-oriented scripting language based on the ECMAScript standard. The latest version, ActionScript 3, is based on ECMA-262 4th edition that was proposed but never approved and published. The syntax and object-oriented features are very similar to Java; you define and extend classes, define and implement interfaces, and use the private, public, protected, and internal (package) namespaces. Different from Java, you use curly braces inside the package keyword when defining classes, you use the function keyword to declare methods, and you use post-colon data typing instead of the data type prefixes used in Java. Data typing is also optional. You can type everything for IDE code-hinting and compile and runtime type checking, but you can also use dynamic typing when appropriate for flexibility.
MXML is a convenience language; it provides an alternate way to generate ActionScript using a declarative tag-based XML syntax. When you compile an application, the MXML is parsed and converted to ActionScript in memory and then the ActionScript is compiled into bytecode, your SWF. Although you never have to use MXML, it is typically used to define application interfaces (for layouts, the MXML code is usually more succinct and understandable than the corresponding ActionScript would be) and ActionScript is used to write the application logic. Just as you break up your logic into separate ActionScript classes, you also break up your MXML code into separate reusable MXML components, separate ActionScript classes.
Granite DS is a free, open source alternative to LiveCycle Data Services (discussed below), providing a framework for Flex/EJB 3/Seam/Spring/Guice/POJO application development with full AMF3/RemoteObject benefits.
Midnight Coders offers WebORB for Java for connecting Flex (and Flash, AJAX and Silverlight clients) with Java objects, Spring Beans, EJB (v1 or v3) or XML Web Services, native operating system resources and rich media streams (audio and video).
You can choose from several different server-side Flash Remoting implementations for Java servers. BlazeDS is a free, open source version created by Adobe that provides server-side Java remoting as well as a web messaging technology to push data in real-time to Flex applications. The messaging service also enables Flex applications to exchange messages with other non-Flex, JMS-enabled applications.
You can use a combination of the remoting and messaging services to create real-time, data-centric applications. When a user changes some data in this type of Flex application, the data is saved in the database on the server, and then pushed out to all the other clients currently accessing the data so users always see the most up-to-date data. To create this type of data synchronization, you must write quite a bit of code to save the data on the server, push the data out to the other clients, and manage any data conflicts. Alternatively, you can use LiveCycle Data Services, which provides much of this code for you (see the Adobe LiveCycle Data Services section below).
SpringSource and Adobe have partnered to create a special version of BlazeDS, the Spring BlazeDS Integration, whose purpose is to streamline the integration between Spring and BlazeDS. Instead of having Spring and BlazeDS as two side-by-side systems with different configuration files and only a basic communication mechanism, the Spring BlazeDS Integration lets Spring manage BlazeDS just as it manages the other components of an application. You can also get started with the Spring BlazeDS Integration Test Drive, a turnkey solution containing a minimal version of Tomcat and the Spring BlazeDS Integration pre-configured and ready to use with a set of samples.
Adobe LiveCycle Data Services is a super set of BlazeDS and provides a complete data infrastructure for enterprise Flex applications. In addition to providing the remoting and messaging services available with BlazeDS, it also provides a data management service that can help reduce development and maintenance costs for real-time, data-centric applications.
The data management service automates data synchronization between a Flex application and the middle tier, providing data synchronization, conflict resolution, paging and lazy loading, management of large collections of data and nested data relationships (such as one-to-one and many-to-one associations), integration with Hibernate, offline data access in AIR applications, and more. You can add many of these advanced data management service features to your applications without writing any server-side code using modeling technologies introduced in LiveCycle Data Services ES2 (see the following two sections).
LiveCycle Data Services also provides advanced deployment options for maximum scalability, streaming with the Real Time Messaging Protocol (RTMP), PDF generation, portal integration, LiveCycle connectivity, access to developer and enterprise support resources, and more. See the LiveCycle Data Services and BlazeDS comparison chart for more details.
Flex applications can communicate with back-end servers using either direct socket connections or more commonly, through HTTP. You can make HTTP requests (to JSP or XML files, RESTful web services, or other server files that returns text over HTTP), web service requests (to web services that return SOAP formatted text over HTTP), or Flash Remoting requests (to methods of server-side Java classes that return binary Action Message Format over HTTP). When possible, use Flash Remoting whose binary data transfer format enables applications to load data up to 10 times faster than with the more verbose, text-based formats such as XML, JSON, or SOAP.
Flash Remoting is a combination of client and server-side functionality that together provides a call-and-response model for accessing server-side objects from Flash Platform applications as if they were local objects. It provides transparent data transfer between ActionScript and server-side data types, handling the serialization into Action Message Format (AMF), deserialization, and data marshaling between the client and the server. Flash Remoting uses client-side functionality built in to Flash Player and server-side functionality that must be installed on the application server.
Flash Remoting is built in to some servers (such as ColdFusion and Zend) but must be installed on other servers (as BlazeDS or LiveCycle Data Services on Java EE servers, WebORB or FluorineFX on .NET servers, the Zend framework or amfphp on PHP servers, and more).
Action message format (AMF) is a binary format used to serialize ActionScript objects and facilitate data exchange between Flash Platform applications and remote services over the Internet. Adobe publishes this protocol; the latest is AMF 3 Specification for ActionScript 3. Refer to the documentation for tables listing the data type mappings when converting from ActionScript to Java and Java to ActionScript.
The Adobe application modeling technology (codenamed Fiber) is a set of technologies that together enable model driven development for Flex applications, which simplifies the development of data-centric Flex applications.
In Flash Builder 4, the application modeling technology is used when creating and working with an ActionScript data service that maps to a server-side service (a Java class with a no argument constructor and public methods). When you create the ActionScript data service, Flash Builder generates ActionScript classes and code for calling the remote service and manipulating the corresponding data transfer objects (also called value objects). ActionScript classes are created that map to the corresponding Java objects manipulated by the methods of the Java class (which often correspond to records in database tables). You can then manipulate the same types of objects on the client and on the server and pass instances of them back and forth between the two.
If you are using LiveCycle Data Services, the generated client-side code uses LiveCycle specific classes to also provide the additional data management features discussed previously.
If you are using LiveCycle Data Services ES2, you can download and install the Adobe application modeling plug-in for Adobe Flash Builder, which is a graphical modeling editor to automatically generate server-side code in addition to client-side code.
You can use the Modeler to define a model based on an existing database and then have it generate and deploy the client-side code, the server-side code, and the server-side configuration files needed to manipulate this data. If you are starting from scratch and the database tables don't exist yet, you can use the Modeler to define a model and then have it generate the database tables in addition to generating the client and server-side code to manipulate this data.
Instead of hosting and managing your own data messaging service, you can also use one of the Adobe Flash Platform services, the Collaboration service, which provides real-time collaboration features, including chat, audio, and video. Other Flash Platform services include the Distribution service (for distributing, promoting, tracking, and monetizing applications on social networks, mobile devices, and desktops) and the Social service (for integrating with multiple social networks including Facebook, MySpace, Twitter, Yahoo, Google, and AOL using a single ActionScript API).
This article introduced the technologies involved in building Flex and Java applications. For additional information about these technologies, use the following resources: