*** Update: 8.14.2007: The code in this article is out of date. Please refer to the new entry instead. ***
This example utilizes Amazon’s search webservice in the Cairngorm 2 application framework. You can go to Amazon.com and register for a free API key. Once you do, you just plug into this example’s constant file, and she’ll work for you too if you when you compile. This example application allows you to search for books on Amazon.com by keywords.
The events are debatable in their place in the package structure. They extend CairngormEvent, thus implying they fire commands, but you could reuse events. Also, I am not very good at E4X so please do not use that as an example of E4X usage.
Here’s basically how she works:
- App boots up, shows first state
- user types in some keywords, clicks the Search button
- this fires the doSearch event handler
- the doSearch handler creates a CairngormEvent, and dispatches it
- the Controller has mapped that type of event to a Command, and thus it runs the command, passing it the event
- the Command looks at the event type in the execute function and decides what to run, in this case, searchBooks, passing the event’s data to the function
- search books creates the Business Delegate, and calls its method
- the Delegate gets the WebService from the ServiceLocator, fires off the WebService, and waits for a response
- if the response is successful, it parses the E4X XML via a Factory to a list of Book ValueObjects
- finally, it calls the responder’s onResult function
- Since the Command is the Responder, he gets the data, and sets it to the ModelLocator and updates the applications state
- The View’s are bound to the state variable and book list in the ModelLocator, so they immediately have their bindings fire
- This causes the main app to change state, and show the results DataGrid
- The results DataGrid is bound to the books list in the ModelLocator, and shows the results.
* Note: I haven’t got my serial for Flex Builder 2 yet, so the App & View Source will time out after a day. The source, however, is good forever.
BTW, I fixed my Atom feeds, thanks to those who let me know they were busted. If I don’t know it’s broke, I can’t fix it.