Learning Flex 4 | O'Reilly Media

The Book’s Source Code by Chapter

with 11 comments

Just in case people come here looking for the book’s example code:

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16


[Update: It seems the Yahoo searching service has gone offline. I modified the code from pages 232-233, as follows, and using debugging techniques, I see that the application is catching errors in the searchFault() method.]

<?xml version=”1.0″ encoding=”utf-8″?>
<s:Application xmlns:fx=”http://ns.adobe.com/mxml/2009
import com.yahoo.webapis.search.events.SearchFaultEvent;
import com.yahoo.webapis.search.events.SearchResultEvent;
import mx.collections.ArrayCollection;

private var searchResultAC:ArrayCollection;

private function onSearch():void {
searchService.query = queryTI.text;

private function searchResult(e:*):void {
// breakpoints here won’t hit…………………….
searchResultAC = e.result as ArrayCollection;
resultsList.dataProvider = searchResultAC;

private function searchFault(e:SearchFaultEvent):void {
// this breakpoint catches every time…………
<yahoo:SearchService id=”searchService”
<s:VGroup left=”10″ right=”10″ top=”10″ bottom=”10″>
<s:Label text=”Yahoo! Search:” fontWeight=”bold”/>
<mx:FormItem label=”Query:” fontWeight=”bold”>
<s:TextInput id=”queryTI” width=”350″/>
<s:Button id=”searchButton” label=”Search”
<s:List id=”resultsList” width=”100%” height=”100%”/>

This screenshot came right out of FlashBuilder 4.5, with a breakpoint set in the searchFault() method:

The Variables pane showing errors attached to the SearchFaultEvent object.

I’ll give this problem some thought. Perhaps I can post an alternative API example here. Does anybody have an API they’d like to recommend for an example application? If so, I’m open to suggestions.


Written by elrobis

7 November 2010 at 11:13 pm

Posted in Uncategorized

11 Responses

Subscribe to comments with RSS.

  1. I can’t figure out how to load your “learningFlex 4” package in Chapter 5. Where do we download the package from?


    28 November 2010 at 9:55 am

    • Hey there. The source for that Chapter is actually two FXP projects bundled in an every day ZIP file. I’m assuming you already have the Chapter 5 ZIP downloaded. If you unzip it, you’ll get two FXP files. These are a proprietary compressed file type Adobe created for Flex Projects/Flash Builder.

      You can load an FXP file in Flash Builder by following:
      File > Import > Flash Builder Project

      In the dialog select “File” and browse to one of the FXP files you unzipped for Chapter5. Flash Builder should then unpack the project in a unique directory.

      I’m glad you asked about this as I wondered if it might create some confusion. That’s what I get for writing the entire book before working on the companion site. :/

      Best, Elijah


      28 November 2010 at 10:09 am

    • Hi,
      When I import BusySkin-15-20-thru-23.fxp
      it can’t find:
      import learningflex4.skins.GraphicButtonSkin;
      there is no ‘learningflex4’ folder, ie – there is no GraphicButtonSkin file


      20 July 2011 at 7:27 pm

      • Same with YahooSearch-15-14-thru-16.fxp
        can’t find:
        import learningflex4.skins.SearchButtonSkin;


        20 July 2011 at 7:35 pm

      • hi Steve, when Flash Builder imports the FXP, perhaps it isn’t creating the learningflex4 package in the default workspace. You can fix this by following the steps at the bottom of pg 79 and the top of page 80, where I describe creating a file path / package directory, then adding it to the project’s build path. Supplement this with the details between 328-333, where you create a skin class and meld it into the YahooSearch app. Review and apply the steps noted in those pages and I believe you’ll be set for both the SearchButtonSkin.

        As for the GraphicButtonSkin, I believe that one emphasizes skinning by studying a component’s Skin parts, creating an FXG graphic, and linking it into a custom Skin class. There is a little more work involved for the GraphicButton, as I recall you create a custom component to go with it. All the details should be discussed in the last half of Chapter 15, though. I think if you create the package as discussed on pages 79/80, and link it into your project’s build path, your troubleshooting will start heading in the right direction. /E


        21 July 2011 at 7:51 am

  2. Hello , Connecting to Search Results , page 231 , doesn’t work , when I search on the text input , it doesn’t show anything in the list box , what is the problem ?


    27 September 2011 at 5:41 am

    • @anfoolanza, hi. Hmmmm… I can confirm the search app is failing, and it seems the Yahoo ASTRA search service is offline. I modified the application to dispatch and receive the search in ActionScript blocks, and sure enough it’s throwing web faults. I’ll see if I can attach a screenshot to my reply here; however, I copied the URL the ASTRA library is creating (I found it by digging around in Debug mode > Variables pane), and when I throw this URL into a web browser, it bombs:


      I can see from the Yahoo page that Yahoo has deprecated their ASTRA library. What I don’t know is whether it is termporarily or permanently offline —if it’s permanent, I’m disappointed the library remains available for downloading (i.e. I just downloaded it again to see if the code base changed, and I had no problem finding it or downloading it). If you’re interested, I updated my “source code by chapter” post to include some thoughts concerning my findings, as well as my modified source code, which was more conducive to debugging.

      If that Yahoo library is permanently dead, that’s certainly unfortunate for the book. Is there an API you’re interested in using, for which you would like to see an example Flex application? If so, I’d be happy to consider a couple recommendations; perhaps I could whip up something and post the example here. Please let me know.

      Best, Elijah


      27 September 2011 at 10:16 am

  3. Dear Elijah , really , I love your book, , I’ve been used flex before , I use your book for reviewing flex .When I saw your book for the first time , I realized that the book is very well written and it is an excellent book for starting flex , but what should I do then , all of the chapters relies on this yahoo service , I think it will disturb the validity of the book , would you please update your source code and tell it all around the web , or make companion pdf for changing the original book . I appreciate your reply


    27 September 2011 at 10:16 pm

    • @anfoolanza, please see my latest post (Google Search Application in Flex 4), which addresses your concern here. As I’m in the middle of a work-week, this is a quickly-cobbled replacement for the YahooSearch example, and perhaps I didn’t explain things well-enough. I’d appreciate if you’d give me some feedback. I’ll return to that post over the weekend and “seed” it with some more discussion, as well as add the project to my source code downloads.


      29 September 2011 at 10:13 am

  4. Code download link is not working


    30 January 2015 at 11:33 am

    • Thanks for letting me know. I moved the code to an active domain and fixed the links. /E


      3 February 2015 at 9:20 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: