Programming Flex 2 – Book Critique
There are many formats in which to write a technology book, such as those nutshell, cookbook, and dummy book formats. There are also a set of books that introduce you to a subject from a distance, those that provide a ton of nitty-gritty code snippets, and those that build a sample, yet trivial, application. I would classify Programming Flex 2, jointly produced by O’Reilly and the Adobe Developer Library, as a high-level introductory text for Flex 2 so that managers that have not written a line of code since Fortran can put it on their bookshelf. I feel that a better suited name for this book might have been ‘A Nice Review for Thinking About Programming Flex 2’ as it does not provide enough reference material to actually program a useful application. Programming Flex 2 is a nice overview of the programming environment for Flex but in my blunt opinion it does not give enough depth in any of the topics it tries to cover. The book breaks down the Flex 2 SDK into the following 19 chapters…
Introducing Flex
The introductory chapter on Flex 2 goes over how Flex runs on top of the ubiquitous Adobe Flash player. The author touts the market share of the Flash plugin which is thought to be installed in nearly 98% of all internet enabled machines.
The Flex platform is based on standards such as XML, HTTP, Web Services, and ECMAScript and leverages rich media support in Flash. The Flex Framework consists of libraries for UI controls such as buttons, text fields, menus, layout containers, data containers, effects, and more which are used to build interactive UI clients. You can program Flex 2 applications coding markup code by hand or break down and shell out close to $500 on Flex Builder 2, a Eclipse-based commercial-grade IDE.
Building Applications with the Flex Framework
This chapter provides a bit more detail into MXML, the markup used in Flex, and ActionScript. MXML is compiled into ActionScript which is then converted into a SWF Flash file. Flex 2 SDK comes with two compilers, mxmlc and compc, to build Flex applications. This chapter goes over the details on how to compile a Flex application using the command line and the mxmlc compiler.
MXML
With the obligatory introduction out of the way, this chapter introduces the MXML markup language used to write Flex applications. MXML is a markup language like XML or HTML, so proficient web developers and designer will pick it up right away.
Here is the take away from this chapter. There are two available root nodes for MXML documents, application and canvas. An application is made of components, such as buttons or text fields. There are several types of components, visual just as buttons and non-visual such as data. MXML supports events similar to the onclick events provided in HTML.
ActionScript
This chapter dives into the details of ActionScript 3. ActionScript is the object-oriented programming language used to create Flex applications. ActionScript is a superset of ECMAScript, the ECMA standardized JavaScript specification. You can mix ActionScript inline and embedded in MXML source files for event handling or business logic. The rest of the chapter deals with the nitty-gritty details of creating classes, properties, arrays, objects, and interfaces in ActionScript.
ActionScript has native support for XML. You can create XML literals such as the following code snippet.
var xml:XML = <entry> <author> <name>Juixe TechKnow</name> </author> </entry>;
Framework Fundamentals
This chapter describes the life cycle of a Flex application. In essence, since a Flex application is just a Flash movie, all Flex applications inherit from flash.display.MovieClip. Flex applications are Flash movie clips with just two frames, a loading frame and the application frame.
The application life cycle include preinitialize, initialize, creationComplete events.
This chapter differentiates the Flash player and the Flex 2 framework. The Flash player is the VM which runs SWF bytecode generated by the Flex compiler. Flash movies and Flex applications both can on the Flash Player. The Flex framework is just an abstract layer on top the Flash Platform specifically for building GUI applications.
Managing Layout
This chapter discusses and provides usage examples of the different layout managers available in Flex. Right out of the proverbial box, or download, the Flex SDK makes available horizontal and vertical containers to layout child UI components. You can also use a grid layout manager for more precise positioning of child components.
Working with UI Components
This chapter runs down through the Flex UI components such as buttons, text fields, combo boxes, windows and more. Flex UI components inherit from FlexSprite and share properties such as x, y, width, height, visible, enabled, and more.
This chapter touts how the model-view-control (MVC) pattern is baked into Flex components. In Flex lingo, data models are known as data providers.
Framework Utilities and Advanced Component Concepts
This chapter chapter functions as an auxiliary chapter to Working with UI Components as it describes additional UI elements such as tool tips, pop ups, drag and drop, and keyboard control.
Working with Media
Flash has been the de facto technology for delivering rich media such as video, audio, and animation on the web. This chapter describes how Flex can leverage rich media.
This chapter covers loading additional resources at runtime, embedding them at compile time, or streaming rich media files.
Managing State
The tenth chapter of Programming Flex 2 describes how to add and remove Flex UI components, set properties, or set styles using states. Flex states are collections of changes applied to a client view. Flex states are interesting as they allow you to build dynamic and customizable clients.
Using Effects and Transitions
As mentioned earlier, Flex 2 applications compile down to SWF files which run on the Flash player. From the beginning, Flash has been designed to provide a rich visual effects. This chapter describes the different effects available in Flex 2 applications such a blur, move, fade, dissolve, glow, resize, rotate and more. You can apply an effect either in MXML or ActionScript You can build composite effects and have them run either in sequence of in parallel. You can create custom effects by extending the EffectInstance class.
Working with Data
As described earlier, data models are known in Flex as data providers. This chapter describes how to bind data providers to Flex UI components. Literal data, whether in XML or ActionScript data structure, can be embedded in MXML source or loaded at run time from an external file. In most situations you will use ActionScript to create your data providers at run time based on business logic or Web Services.
Validating and Formatting Data
In addition to data binding, a UI framework like Flex needs to address data validation and formatting issues. This chapter explains the Flex capabilities in validating user entered data and formating mechanism before data is binded to a client view component. You can create custom ActionScript validators or use those available by the framework, such as the string, number, date, and phone validators amongst others. Like all things Flex, you can use validators either in your MXML or ActionScript source code.
In addition to a number of validator, Flex comes with a series of data formatters, such as number, date, currency, phone, etc. This chapter also describes how to extend the base Formatter to create custom ActionScript formatters.
Customizing Application Appearance
The Flex framework allows you to change the look and feel of your application at run and compile time. This chapter breaks down how to apply styles and change skins for your Flex application. In Flex, styles allow you to customize your applications color, size, and other attributes through CSS. You can update a CSS class in ActionScript via the StyleManager.
Flex skins are more akin to Java Look and Feel libraries which might change the shape and theme of UI components. Skins allow for more customization and greater control of the look and feel of your Flex application.
Client Data Communication
Data communication on the client side. There are three types of client side data communication. Client side communication use low level Flash API ActionScript.
Local connections allows two .swf files to send data to each other even if they are running on different Flash Player instances.
Local shared objects are temporary files written to and read from the client machine but managed by the Flash Player. Think of local shared objects as cookies. Shared objects are basically a map container for name/value pairs.
The external interface method of data communication allows you to send synchronous method call from a Flash Player to the host application. Since the Flash Player usually runs as a plugin in a host application, i.e. a browser, the external interface communication method is useful to send message to the host application.
Remote Data Communication
This chapter briefly discusses the three remote methods for communicating back to the server. You can use an HTTPServevice or WebService component to post and get from your server. The Flash Player also supports two types of sockets, XMLSocket and a regular ol’ Socket. You can also use the FileReference component for file upload functionality.
Application Debugging
I love debugging, and at first I though this chapter was far too slim to cover such an import topic. The author did into some details regarding Flex runtime errors, debugging with FDB/Flex Builder, remote debugging, tracing, and logging. FDB is a free command-line debugger that is made available with the Flex SDK. You need to configure tracing explicitly in the mm.cfg file. You can invoke the trace(String) method to trace a debug message, or the Log class. The end of the chapter has a small section of debugging network application using data inspectors or packet sniffers such as ServiceCapture and Wireshark.
Application Components
Breaking up an application into reusable chunks, classes, packages, or components is vital to developing large systems. This chapter goes into the basic of dividing a Flex application into component MXML or ActionScript files. Basically a MXML file is compiled into ActionScript which then gets compiled into Flash bytecode. Since a MXML file is basically an ActionScript class you can mix and match between markup and script code. You can create your own components by creating a MXML file whose root node is a Canvas instead of Application. Custom child components have levels of encapsulation and data hiding but you can add properties, getter/setter, methods, and events to custom components.
Building Custom Components
The last chapter of the book covers some advanced features for developing custom components such as the life cycle that components go through. The life cycle of a Flex component is made up of three key phases, initialization, update, and destruction. The most important classes used to develop custom components are UIComponent and Container. For you custom components you will most likely implement any, or all, of the following methods: createChild, commitProperties, measure, and updateDisplayList.
Technorati Tags: flex, flash, flexbuilder, mxml, actionscript, adobe, book, review