Thursday, January 26, 2006

Macromedia FLEX and Java

I was just skimming through Macromedia Flex and I should admit, it"s very impressive.


It seems to be a pretty good way to create Rich Internet Applications (RIA). Since the flash player is already available in millions of computers, it is fast becoming a standard to deliver RIAs and it might even replace quicktime and other media applications. And Flex provides the perfect server side component for Macromedia to take advantage of all those computers with flash.


Macromedia Flex is a presentation server that developers are using to build a new generation of Rich Internet Applications (RIAs). Rich Internet Applications combine the usability of desktop applications with the administrative advantages of the web.


The Flex language capitalizes on the strengths of two popular development paradigms: markup languages and object-oriented programming languages.


Check out a HelloWorld.mxml (Classic Hello World example, this time in flex). You define the user interface declaratively using MXML and write the copy logic in ActionScript in the click event handler for the Button component.

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">

<mx:TextInput id="source" width="100"/>
<mx:Button label="Copy" click="destination.text=source.text"/>
<mx:TextInput id="destination" width="100"/>

</mx:Application>

The first time a user requests HelloWorld.mxml, the server compiles the MXML code into Flash bytecode (a SWF file). The server then sends the generated SWF file to the client where it executes in Flash Player. Subsequent requests to the same MXML document bypass the compilation process


Now, where does this fit in with J2EE?


Flex is a presentation server installed on top of a J2EE application server or servlet container, a rich library of user interface components, an XML-based markup language used to declaratively lay out these components, and an object-oriented programming language which handles user interactions with the application. The result is a Rich Internet Application rendered using Flash Player and developed using industry standards and a development paradigm familiar to developers.


Developers use two core languages to create Flex applications. The first core language is MXML, the Macromedia Flex Markup Language, which includes a rich set of XML tags that allows developers to layout user interfaces. MXML can also be referred to as an XUL, or XML UI Language. These tags can be extended, unlike HTML, with additional capabilities that the application requires. Other MXML constructs allow you to call remote objects, store data returned in a model, and customize your own look and feel to MXML components.


The second core language for Flex development is ActionScript 2.0, which is an ECMA-compliant language similar to JavaScript. ActionScript elements are coded inside MXML pages. This is a strongly typed object-oriented language that should be familiar to Java developers. ActionScript also has robust event handling capabilities to allow the application to respond to dynamic user interactions. Because ActionScript runs inside the Flash plug-in, there is no need to rewrite several versions of the same code to support different browsers. This may not be the case with JavaScript code in a browser. Both MXML and ActionScript are text-based languages and can be written in a simple text editor, an IDE tool such as Eclipse, or a more sophisticated tool like the Flex Builder from Macromedia. If you have experience with Java, XML, and a scripting language such as JavaScript, you will experience a small learning curve to Flex development.


The Flex server is responsible for translating the MXML and ActionScript components into Flash bytecode in the form of .SWF files. This process is similar to compiling JSP files into servlets by a Java web application container. The SWF file is executed on the client in the Flash runtime environment. The Flex server provides other services such as caching, concurrency, and handling remote object requests.


For a great example check out http://maps.yahoo.com/beta/index.php which is all Flex based. Wow!


Talkbacks and comments always welcome.

No comments: