Developers > AS2 Learning Center > RSS Widget Tutorial
Welcome to the RSS Widget Example. In this lesson you'll learn how to make a Digg RSS feed widget in 16 lines of code. You can download the source code for this example rss.zip
Requirements
Introduction to the RSS Parser We've included a RSS parser along with the yourminis API in order to make it easy for anyone to work with RSS or ATOM feeds. With the RSS parser we've included, you can even parse feeds that require Basic Authentication. The parser also automatically proxies your requests, so you don't have to worry about domain security issues.
Methods
There is only one method for the RSS Parse which is aptly named "parse". The parse method takes the following parameters:
Events
Steps 1. Add a list to the stage
For the sake of this example, add a V2 component to the stage at around x=4 and y=30 and give it an instanceName of "list". When you're actually creating widgets for yourminis, please don't use the V2 components as they make the widgets very large in file size. For instance, our fully featured RSS widget in yourminis is around 38KB and the file from this example ends up being 53KB.
2. Add the Youminis API and a resize Listener
Since this was covered in the Advanced Tutorial, I'll just provide the code without an explination here.
3. Create the onLoadRSS listener Once our feed is parsed, the onLoadRSS event is fired. The result of the parsing is an array of all of the feed items. Each element is accessible as if the item were an object. If you wanted to access the title of the item, you would write something like items[0].title. For our example we'll list the title of the item in the list and have the link be the data that is passed into the list item. Later we'll set up our widget to open that link when you click on it's corresponding item in the list. Here is how to set up the listener.
Now, once the RSS parser is done parsing the feed, it'll add all of the items to the list.
4. Make clicking on an item open up it's link
Again, since this step is more related to the V2 list than the yourminis API, we'll just prove the code and if you have questions, please refer to the Flash documentation.
5. Get and Parse the Feed
Since we've already set up our listener, the only thing let to do is to tell the rss parser to go a head and fetch the feed and parse it. In this example, we'll grab the main feed from www.Digg.com. To execute the RSS parser, enter the following code:
That should be it! If you press the "Test this mini!" button in the yourminis API panel, your widget should look like this:
Requirements
- Adobe Flash 8
- Latest yourminis API mxp (If you don't have this installed yet, follow the steps found here)
Introduction to the RSS Parser We've included a RSS parser along with the yourminis API in order to make it easy for anyone to work with RSS or ATOM feeds. With the RSS parser we've included, you can even parse feeds that require Basic Authentication. The parser also automatically proxies your requests, so you don't have to worry about domain security issues.
Methods
There is only one method for the RSS Parse which is aptly named "parse". The parse method takes the following parameters:
- url: String - The url of the RSS feed to parse
- username: String - (optional) The username if the RSS feed requires Basic Authentication
- password: String - (optional) The password if the RSS feed requires Basic Authentication
Events
- onLoadRSS - Once the RSS parser has successfully parsed the RSS feed, the onLoadRSS event is fired
- onInvalidFeed - If the feed cannot be loaded or is invalid, the onInvalidFeed event is fired
- onUnauthorized - If the feed requires authentication, the onUnauthorized event is fired
Steps 1. Add a list to the stage
For the sake of this example, add a V2 component to the stage at around x=4 and y=30 and give it an instanceName of "list". When you're actually creating widgets for yourminis, please don't use the V2 components as they make the widgets very large in file size. For instance, our fully featured RSS widget in yourminis is around 38KB and the file from this example ends up being 53KB.
2. Add the Youminis API and a resize Listener
Since this was covered in the Advanced Tutorial, I'll just provide the code without an explination here.
var ym_api:yourminisAPI = new yourminisAPI();
ym_api.onResize = mx.utils.Delegate.create(this,doResize );
function doResize( w:Number, h:Number ):Void {
list.setSize( w-8, h-38 );
}
3. Create the onLoadRSS listener Once our feed is parsed, the onLoadRSS event is fired. The result of the parsing is an array of all of the feed items. Each element is accessible as if the item were an object. If you wanted to access the title of the item, you would write something like items[0].title. For our example we'll list the title of the item in the list and have the link be the data that is passed into the list item. Later we'll set up our widget to open that link when you click on it's corresponding item in the list. Here is how to set up the listener.
ym_api.RSS.onLoadRSS = mx.utils.Delegate.create(this,onLoadRSS);
function onLoadRSS( items:Array ):Void {
for( var i = 0; i < items.length; i++ ){
list.addItem( { label:items[i].title, data:items[i].link } );
}
}
4. Make clicking on an item open up it's link
Again, since this step is more related to the V2 list than the yourminis API, we'll just prove the code and if you have questions, please refer to the Flash documentation.
function change( evtObj:Object ):Void {
getURL( evtObj.target.value, "_blank" );
}
list.addEventListener( "change", this );
5. Get and Parse the Feed
Since we've already set up our listener, the only thing let to do is to tell the rss parser to go a head and fetch the feed and parse it. In this example, we'll grab the main feed from www.Digg.com. To execute the RSS parser, enter the following code:
ym_api.RSS.parse( ym_api.getRssProxyUrl( "http://digg.com/rss/index.xml" ) );
Next Steps
As you can see, we've made it extremely easy for you to get and parse RSS feeds.
yourminis 