RSS parser package enables developers to handle RSS (currently rss2.0 only) easily in their flash content with ActionScript 2.0. This package includes features of loading RSS via network, parsing RSS tree and storing its data as Object instance of ActionScript for flash developer's use.

Contents

Download

Download: rssParser-0.22.zip ( version 0.22, released on 24/May/2006 )

Usage

Preparation

Unzip downloaded file and copy the package (whole "com" folder) to predefined path. You can set the package into...

1. The document-level classpath where same path as your ".fla" document files exists.
...or
2. The global classpath listed below where that's shared by all of your Flash documents.

Windows
(Hard disk)¥Documents and Settings¥(User)¥Local Settings¥Application Data¥Macromedia¥Flash 8¥(Lang)¥Configuration¥Classes

Macintosh
(Hard disk)/Users/(User)/Library/Application Support/Macromedia/Flash 8/(Lang)/Configuration/Classes

Simple sample

This simple sample loads RSS feeds and shows its Object tree in trace window of flash IDE.
Import sentence is required for use of this package as line 2 in this sample code.

// import package
import com.cybozuLab.rssParser.*;

// create FetchingRss class instance
// set the target RSS URL
var rssObj:Object = new FetchingRss( "http://www.example.com/index.xml" ); // change exist URL

// pointer to this MovieClip
var thisObj = this;

// define the function when loading is completed
rssObj.onLoad = function( successFL, errMsg )
{
	if( successFL )
	{
		// trace the object, result of parsing
		Utils.traceObj( this.getRssObject() );
	}
	else
	{
		trace( errMsg );
	}
}

// start loading
rssObj.load();

Simple sample 2

This simple sample loads RSS feeds and shows its posts summary in trace window of flash IDE.

// import package
import com.cybozuLab.rssParser.*;

// create FetchingRss class instance
// set the target RSS URL
var rssObj = new FetchingRss( "http://www.example.com/index.xml" ); // change exist URL

// pointer to this MovieClip
var thisObj = this;

// define the function when loading is completed
rssObj.onLoad = function( successFL, errMsg )
{
	if( successFL )
	{
		// call function for listing summary
		thisObj.listSummary();
	}
	else
	{
		trace( errMsg );
	}
}

// start loading
rssObj.load();


function listSummary()
{
	var rssData:Object = rssObj.getRssObject();

	for( var i=0; i<rssData.channel.item.length; i++ )
	{
		var post:Object = rssData.channel.item[i];

		trace( "---------------------------------" );
		trace( post.pubdate.value );
		trace( post.title.value );
		trace( post.description.value.substr( 0, 60 ) + "\n" );
	}
}

Other samples

Reference

Class: com.cybozuLab.rssParser.FetchingRss
Constructor
FetchingRss Constructor
public FetchingRss( url:String )
Creates a new FetchingRss object. You must use the constructor to create an FetchingRss object before you call any of the methods of the FetchingRss class.
Parameters
  • url:String --- A string that represents the URL where the RSS feed to be loaded. If you let the SWF running in a web browser issue this call, the url must be in the same domain as the SWF file. (You can get feeds in other domains via web proxy in your domain.)
Example
The following example creates a new object.
var myRss:FetchingRss = new FetchingRss( "http://www.simple-example.com/somebody/index.xml" );
Event
onLoad Event Handler
public onLoad = function( success:Boolean, errorMessage:String ) {}
Invoked by Flash Player when parsing of RSS document is completed after receiving from the server. If the RSS document is received and parsed successfully, the success parameter is true. If any error occurred in receiving the data from the server or in parsing the data, the success parameter is false. The default, this method is not active. To activate, you must assign a function that you define.
Parameters
  • success:Boolean --- A Boolean value that evaluates to true if the RSS data is loaded and parsed successfully. Otherwise, false.
  • errorMessage:String --- A String that represents the detail of error status.
Example
See the "Simple sample" in "Usage" chapter. If any error happens, error message is dumped in trace window.
Method
getErrorMessage Method
public getErrorMessage():String
Returns a string of error message predefined. Return value of this method show you detail information for debugging.
Return
String --- A string of the predefined erro messages.
Example
The following example shows error messages in trace window when the loading is failed.
import com.cybozuLab.rssParser.*;

rssObj = new FetchingRss( "http://www.example.com/index.xml" );

thisObj = this;
rssObj.onLoad = function( successFL ){
	if( successFL ){
		trace( Utils.objToString( thisObj.rssObj.getRssObject() ) );
	}else{
		trace( thisObj.rssObj.getErrorMessage() );
	}
}

rssObj.load();
getRssObject Method
public getRssObject():Object
Return an Object contains parsed RSS data tree. This method should be called after the onLoad event handler is invoked.
Return
Object --- An Object contains parsed RSS data tree.
getRssXml Method
public getRssXml():XML
Return a XML object of RSS loaded from target URL. This method should be called after the onLoad event handler is invoked.
Return
XML --- A XML object of RSS.
getTargetUrl Method
public getTargetUrl():String
Return a string of URL set by constructor or load method.
Return
String --- A String of target URL.
load Method
public load( url:String ):Void

Loads an RSS document from the specified URL, and parses downloaded XML object for storing the data in Object instance. The URL is relative and is called using HTTP. The loading process is asynchronous, therefor it does not finish immediately after the load() method is called.

When the XML data finishes downloading and parsing, the onLoad event handler is invoked.

Parameters
  • url:String --- A string that represents the URL where the RSS feed to be loaded. If you set this parameter, load method overwrites the url parameter you passed at creating instance. If you let the SWF running in a web browser issue this call, the url must be in the same domain as the SWF file. (You can get feeds in other domains via web proxy in your domain.)
Return
Boolean --- A Boolean value of false if url parameter is passed to neither this method nor constructor. True otherwise.
traceRssObject Method
public traceRssObject():Void
Dumps the RSS object tree as string in trace window of flash IDE.
Class: com.cybozuLab.rssParser.ParsingRss
Constructor
ParsingRss Constructor
public ParsingRss( sourceData:XMLNode )
Creates a new ParsingRss object. You must use the constructor to create an ParsingRss object before you call any of the methods of the ParsingRss class. Parsing is executed concurrently.
Parameters
  • sourceData:XMLNode --- A XMLNode object that contains the RSS feed to be parsed.
Example
The following example creates a new object.
var myRss:ParsingRss = new ParsingRss( rssNode );
Method
getRssObject Method
public getRssObject():Object
Return an Object contains parsed RSS data tree.
Return
Object --- An Object contains parsed RSS data tree.
traceRssObject Method
public traceRssObject():Void
Dumps the RSS object tree as string in trace window of flash IDE.
Class: com.cybozuLab.rssParser.Utils
Method
countProperty Method
public static countProperty( targetObj:Object ):Number
Return a Number of elements in the Object passed as parameter.
Parameters
  • targetObj:Object --- An Object for counting its elements.
Return
Number --- A Number of elements in the Object.
objToString Method
public static objToString( targetObj:Object ):String
Return a String of an Object tree.
Parameters
  • targetObj:Object --- An Object for converting to a String.
Return
String --- A String that represents the Object tree.
traceObj Method
public static traceObj( targetObj:Object ):Void
Dumps an Object tree as string in trace window of flash IDE.
Parameters
  • targetObj:Object --- An Object for tracing.

Todo

  • Handling multi enclosure tags in each item tag.
  • Let be compatible with RSS 0.9, 1.0 and Atom feed.

Version History

0.22: [24/May/2006]

  • Utils.traceObj handles both of Array and Object

0.21: [18/May/2006]

  • Enebled to access the result with lower-case object key as well as mixed-case.
  • Change the type of return value which contains each item. ( object -> array )

0.2: [14/Feb/2006]

  • Changed the timing of parsing loaded RSS

Links