VIEW THE DEMO
DOWNLOAD THE SOURCE CODE
Syndication feeds have become a popular way to broadcast site content. But like too many web technologies, there are a number of competing standards like RSS and Atom to do the same job, and this can make life hard for developers. Realising this, Adobe has developed a syndication library that hides the differences between the different syndication feed specifications. This tutorial will show you how to use this library.
Download and extract the Adobe XML Syndication Library from here.
Create a new Flex project, and add the xmlsyndication.swc file to the Flex Build Path.
Add the following attribute to the Application element.
applicationComplete="appComplete()"
This sets the appComplete function to be called when the Flex application has been initialised.
Add the following elements to the Application element.
<mx:List dataProvider="{items}" id="feedList" top="10" left="10" right="10" bottom="10">
<mx:itemRenderer>
<mx:Component>
<mx:Canvas>
<mx:TextArea borderStyle="none" width="100%" height="35" wordWrap="true" htmlText="{data.title}" click="{navigateToURL(new URLRequest(data.link))}"/>
</mx:Canvas>
</mx:Component>
</mx:itemRenderer>
</mx:List>
This List will display the RSS or Atom feed titles in a custom ItemRenderer, and open up the links in a webpage when the item is clicked.
All code in a Flex MXML file is contained in a Script element.
<mx:Script>
<![CDATA[
// code goes here
]]>
</mx:Script>
Inside the Script element we import the following packages.
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import com.adobe.xml.syndication.generic.IFeed;
import com.adobe.xml.syndication.generic.FeedFactory;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
import mx.collections.ArrayCollection;
Add the following variables.
private static const FEED_URL:String = "http://rss.adobe.com/en/resources_flex.rss";
[Bindable] private var items:ArrayCollection = null;
The FEED_URL variable points to the location of the RSS or Atom feed that this application will display.
The items variable will hold the individual feed items to be displayed.