Bright Hub
 
Matthew Casperson's Hubfolio

Parse Atom and RSS syndication feeds in Adobe Flex

Article by Matthew Casperson (4,883 pts )
Published on Nov 3, 2009

This free tutorial shows you how to read RSS and Atom feeds in Adobe Flex

Introduction

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.

Adobe Flex RSS and Atom Reader Screenshot

Step 1 - Download the Syndication Library

Download and extract the Adobe XML Syndication Library from here.

Step 2 - Edit the Build Path

Create a new Flex project, and add the xmlsyndication.swc file to the Flex Build Path.

Adobe Flex RSS and Atom Reader Screenshot

Step 3 - Define an entry point

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.

Step 4 - Define the GUI

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.

Step 5 - Import the packages

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;

Step 6 - Add the variables

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.

Search More About:

Follow Matthew Casperson
Receive weekly updates from Matthew Casperson
 
Bright Hub - Science & Technology Articles, Buyer's Guides, How-To Tips and Software Reviews
About Bright Hub | Contact Us | Advertise with Us | Become a Writer | RSS | Site Map | Terms of Use | Privacy Policy | Copyright Policy
©2009 Bright Hub Inc. All rights reserved. Page copy protected against web site content infringement by Copyscape