Hello! Flex 4 is written for experienced developers who are new to Flex, in general, or Flex 4 in particular. It’s organized as a series of 26 independent hands-on tutorials ("sessions"). Its scope is limited but could be a good introduction to Flex.
As is the norm for code-oriented technical books these days the book’s web page offers a download of all the source code presented in the book. I imported about half of the projects into a Flash Builder workspace and they compiled fine and, for the most part, they ran fine. However, I did encounter a couple of oddities which I’ll describe below.
I started importing the sample projects with chapter 1. Code for the first two sessions worked fine but I got a different result than the book in session 3. This session introduces Flex data binding and the first couple of examples in this session were OK but the last one attempts to show a potential gotcha with two-way data binding. The example is intended to show that binding a text field to a member variable will cause an initialized member variable to be overwritten with the (empty) contents of the text field at startup. This would, of course, defeat the initialization.
The book’s screen shot for this example shows two empty text fields that have been bound to a member var. However, when I ran the code my two text fields displayed the field variable’s initialization string—not an empty string. To check that the downloaded code was correct I copied and pasted the code from the PDF into a new MXML app but it worked the same as before. I don’t know why there’s a difference between the book’s results and mine. Perhaps, some change was made to the Flex 4 framework between the time the book’s sample was written and the official release of Flex 4.
There are examples of the book’s content being a bit dated. For example, on p. 31 the following sentence is found:
Once it’s updated for Flex 4, presumably later in 2009, there will be a newer URL.
And several references are made to Flex Builder (which has been renamed to Flash Builder.) This is in a PDF I downloaded in August, 2010. In the preface the author explains that the book’s original incarnation was to be titled Hello! Flex 3 but that a decision was made mid-stream to target Flex 4. So, some of the material was apparently written earlier, before Flex 4.
Code Samples Pack a Lot Into a Little Code
The examples do quickly illustrate the power of the Flex SDK. Even the early examples show some sophisticated features of Flex. For example, on p. 19 the enabled property of a Delete button is bound to the expression taskList.selectedItem != null. This allows the button to be automatically disabled when no element in the list is selected (since the Delete action would then have no meaning).
Also, the XML example project illustrated nicely with very few lines of code the power and flexibility of Flex’s facilities for manipulating XML.
The book assumes no familiarity with ActionScript 3 and introduces the basics. The ActionScript lessons illustrate a number of the language features that are particular to the language. It’s a pretty quick tour which hits a number of language features in no particular order. But it’s useful to give an experienced developer a heads-up on some commonly-used, important language constructs. Examples include:
- the different ways of creating an Object and assigning properties to it
- different ways of creating Arrays and ArrayCollections and some of their commonly used methods
- variable scoping rules that are different from other languages
- the use of the "is" and "as" keywords
These examples tend to illustrate features that are particular to ActionScript which developers who are new to the language need to be aware of.
The object models showing the inheritance trees for some of the common Flex UI widgets were great. I’d love to see a diagram like that showing the entire Flex 4 SDK.
Vague Explanations
I was a bit disappointed with some of the explanations in the book. For example, on p. 18:
Next, we create a Panel whose title is “Todo List.” It has a width and height of 100 percent, meaning it will take up the full width and height that are left after taking into account the padding of the parent application.
This was a missed opportunity to explain what 100% really means. My understanding, based on my experience, is that the 100% is based on the size of the container’s child elements. The phrase used here, "full width and height," is ambiguous. For example, if the application specifies an explicit width and height what impact does that have on child containers specified at 100%? What about when the minWidth/minHeight properties are used? What about if neither is used?
And, in session 13 the example features a List, a DropDownList and a ButtonBar. In each case, the MXML code includes a statement like:
selectedItem="{_lunchChoice}"The variable that is bound to the selectedItem (here, _lunchChoice) was different in each case. That made sense, but what I didn’t get at first was the purpose of the statement. Unfortunately, the text was no help. Here is one of the "explanations:"
"The DropDownList shows the _coffees the pig can choose from, and its selectedItem is bound to the _coffeeChoice."
(The pig is the customer in this fractured "fairy tale.")The other two explanations are the same except for the type of control, the menu item, etc. The fact of binding is pretty clear but why it is bound is not. So, I tried removing the selectedItem code and the app seemed to work just fine without them. However, upon closer inspection I discovered that what didn’t work is initializing the controls at startup. That’s the only reason for it. That’s useful but not obvious and the book’s explanation doesn’t give any inkling of that. Yes, there’s some value to puzzling out this stuff on your own but that’s not why I would purchase a book.
And, in session 15 the following line of code:
var camera:Camera = Camera.getCamera();
gets this explanation: "Get the Camera." Yeah. This reminds me of developers who comment their code the same way:
var camera:Camera = Camera.getCamera(); // Get the Camera.
I’ve seen way too much of that kind of code, so much so, that I’m not surprised when I see it any more. However, I don’t expect it in a book and I am surprised to see it here.
Cairngorm Model-View-Controller (MVC) Framework
Chapter 7, titled Cairngorm in Action: SocialStalkr (Twitter + Yahoo! Maps), was initially of great interest to me as I’ve been testing various MVC frameworks to try and figure out which one(s) would work best for me. I’ve tried several frameworks but haven’t gotten around to Cairngorm as I’ve heard that it has a pretty steep learning curve. So, I figured that this chapter would be a great opportunity for a guided tour. However, when I learned that the book’s example was based on Cairngorm 2 I lost interest. That’s because Cairngorm 3 has been recently released and V3 represents a major departure from V2. Much of what I might learn about Cairngorm V2 would not be applicable to V3. So, I skipped this chapter.
Conclusion
At 210 pages, Hello! Flex 4 is a bit light for a technical book. By contrast, Adobe Flex 4 Training in a Book is 481 pp. and Adobe Flash Builder and Flex 4 Bible weighs in at 1028 pp. Flex is quite a large SDK and even those two books don’t treat the subject exhaustively. So, Hello! Flex 4′s 210 rather small pages only provide a quick introduction to the subject. As I said at the outset, this could be a good introduction for an experienced developer who wants to get a quick handle on Flex’s strengths and weaknesses. But serious Flex developers would probably do better with another book.


{ 2 trackbacks }