Getting Under the Hood of the Macromedia XML News Aggregator Sample Application
Note: You can get the Macromedia XML News Aggregator sample application on DevNet Resource Kit (DRK) Volume 3, which is available until midsummer 2003 exclusively to DevNet Professional and DevNet Essentials subscribers. After midsummer 2003, DRK Volume 4 will release, and DRK Volume 3 and all previous volumes will be available for $99 each.
Find out more about DevNet Subscriptions
>
It seems that everywhere you turn these days, someone is starting a blog. From executives at many large corporations (Microsoft CEO Steve Ballmer is rumored to have one on the company's intranet) to individual designers and developers using Macromedia products, the proliferation of blogs has stunned almost everyone. But the most interesting development to come out of the blog revolution is the growth and power of syndicated XML-based news formats such as Really Simple Syndication (RSS). They make it possible for people to become their own news sources, providing original content to other websites.
Included in DevNet Resource Kit (DRK) Volume 3, the Macromedia XML News Aggregator sample application not only helps you organize the daily deluge of information you scavenge from your favorite news or business RSS feeds, but it helps you learn how to build applications in Macromedia Flash. This article takes a look at what this application is, how we developed it, and how you can modify it for your own creative projects.
What Is the News Aggregator Sample Application?
The Macromedia XML News Aggregator sample application loads RSS/XML news feeds from the Internet and aggregates and organizes them within an easy-to-use interface (see Figure 1). Although it is useful by itself, it is also a great learning tool that demonstrates the following:
- Techniques for creating standalone Macromedia Flash applications
- Loading, parsing, and manipulating XML with Macromedia Flash
- Using components within Macromedia Flash MX
- Storing data with Macromedia Flash MX
Figure 1. The Macromedia XML News Aggregator sample application user interface.
One of the best ways you can learn is from taking apart other people's applications and learning how they approached a challenge, where they succeeded, and sometimes where they could have improved.
That goes for the news aggregator application too. Let's look at what makes the application tick and how we developed it. The following areas can help you in your next project: object-oriented programming, asset organization, application data storage, and use of Macromedia components.
Object-Oriented Programming (OOP): Although this topic could take up many volumes of text, let us just touch on a few points in the news aggregator application. By encapsulating the code into custom classes, we simplified development and ensured that future changes to it are a breeze.
Take, for example, the RSSParser class, which is the first class created for this project. The RSSParser class initializes a single feed, retrieves the XML data from that feed, parses it into an easily accessible ActionScript object, and returns that data, along with any errors that may have occurred during retrieval or parsing. Listing 1 shows a section of the RSSParser class. By encapsulating the code into a single class, we were able to test and debug the RSSParser class completely independent of the application itself.
Another benefit of using OOP is that any application can use this class or even extend it to support future RSS versions and features. This helped us in the final days of development when we realized that certain versions of RSS were not completely supported by the current class. By adding a few lines of code to RSSParser, we were able to support all versions of RSS more fully. We didn't even have to touch any of the other code in the project. Simply put, the benefit of OOP is that it saves you from pulling your hair out when last-minute changes arise.
Asset Organization: One of most important rituals in developing any large-scale application is how to organize and store your classes, components, movie clips, and other assets. You want to ensure that when you come back to the application in a month's time, you haven't forgotten where everything is located so you can quickly update or fix bugs. The Library, when used correctly, provides a perfect place for you to arrange these assets (see Figure 2).
Figure 2. The Library shows all the assets of the Macromedia XML News Aggregator sample application and how they're organized.
As you can see, each of the classes used in the project has its own individual component. If you were to open the component, you would see one layer that contains all the ActionScript for that class. This provides a quick way to access the code within each of these classes and a way for others to see at a glance which custom classes you used in the project. Also, you can easily transfer these component classes to other projects.
When working in a high-pressure environment, you may be tempted to put all your movie clips and custom components at the root of the library tree. By using the same conventions and standards that Macromedia implements in developing its components, you will create an application that others can understand and modify.
Storing custom classes as components provides you with a way to externalize code quickly by using "#include pragma" within each component and referencing the external .as file. You can then use your favorite file versioning system or text editor to edit and store ActionScript code.
Notice that each window that the application uses is stored in its own movie clip. This allows you to add and edit windows that the core application calls and references.
Application Data Storage: When we planned the application, we realized that we would need to cache not only application data and RSS data but also information regarding the current application state (such as the last feed you are exploring). There were two ways you can approach this.
- You can use local shared objects to store data by storing the actual object that stores the data. Although this does have its advantages, such as quickly retrieving and restoring data when the application starts, it does cause some problems. First, it requires you to finagle the code with the objects a little so that Macromedia Flash associates the correct object with the associated class. More importantly, it does not allow you to write functions that can upgrade the data if a new version of the application accessed it, nor does it allow you to easily extend the data storage mechanism.
- The second option provides a much better solution. You create a DataManager class, which provides functions for storing data specific to the application and working with that data. When the application needs to store or retrieve the current data, it references the methods on the class and passes or retrieves the new information. This allows you to create other functions related to retrieving the application data. For example, if you want to create a feature on the application that allows the user to export the current data, you can simply add a method to the DataManager class. This method would create an XML data tree containing the current feeds, cached data, etc. The class would also be able to import and reinterpret the data, making it easy to move the profile within the application to different machines.
Use of Macromedia Components: One of the most important things to take away from the development of the news aggregator application: the built-in power of the Macromedia components. This application uses nine of them from the following resources:
Macromedia Flash UI Component Set
- CheckBox
- ComboBox
- PushButton
- ScrollBar
DevNet Resource Kit Volume 1
- DataGrid
- ToolTip
- ToolTipLite
- Icon Button
- Tree
You did not modify or edit any of the core functionality of the components; you just used them as is. You probably saved hundreds of hours using these ready-made components. By using the built-in formatting properties of these components, you also modified the look and feel of the components to match the overall design of the sample application.
Now that I've explained a little about what's under the hood of this application, let's talk about how you might use or extend the application.
RSS: Not Just for Blogs Anymore
Although the design and functionality of the Macromedia XML News Aggregator sample application might be quite near perfect (OK maybe not, but we can wish), you're probably thinking about how you can change, improve, or update the application to better fit your needs.
Until this point, developers have used RSS predominantly to syndicate news feeds on blogs. This purpose has proven to be remarkably effective but it's only a small segment of what RSS can do. Imagine that you run a development team and are in the final stages of testing a product for release. You have set up a bug tracking system and are trying to keep up to date with the bugs assigned to you. Luckily, your intelligent bug tracking system provides an RSS feed of all your bugs and updates the feed whenever beta testers post new bugs. As the immensely successful developer that you are, you have the RSS news aggregator running in your system tray, where it checks the RSS feed every five minutes. The aggregator updates you instantly when you need to fix a new bug. Your boss realizes your efficiency and speediness in squashing your bugs and gives you a huge raise!
The raise may be wishful thinking, but applying the technology in this way is not. The news aggregator application shows you just one way that Macromedia Flash technology can access outside data structures using RSS. Whether you develop an application in Macromedia Flash to track tasks in a project management system, keep you up to date with the latest CVS commits, or inform your office of the latest sales information, the news aggregator sample application gives you a foundation of classes and techniques that you can use in your next project.
DRK Volume 3 provides you with a number of tools that can help you
create and publish RSS feeds using ColdFusion MX and Macromedia Flash
MX. Also included in this DRK is the news aggregator application's complete
source code and associated files. There are many applications for RSS
syndication that have yet to be uncovered. By using some of the techniques
developed in this sample application, you may just discover new ways
to use this technology tomorrow.
About the authors
Daniel Dura and Josh Dura are Macromedia Flash developers based in Dallas. Together they run Dura Media LLC, one of the leading Rich Internet Application development firms in Texas.Coming from a background programming in such languages as Pascal, C++, and Java, Daniel specializes in building web-based and standalone applications in Macromedia Flash. You can see some of his most recent work in Macromedia DevNet Resource Kit, Volume 3 and on his blog at www.danieldura.com. Daniel hosts an Ask the Experts session on the DRK at Flash Forward 2003 in New York.
Josh is a web, graphics, and application developer at ReadyHosting, Inc. in Richardson, Texas. He has worked with Macromedia Flash since the days of version 4, and has recently created applications for the DRK. He likes to emphasize his work on user-interface design and usability of Macromedia Flash applications. Read more about him at www.joshdura.com.
Submit feedback on our tutorials, articles, and sample applications.