The RSSFeed Class presented in this post was derived directly from the code in the previous post. Parameters passed to the class include the address of the feed and the range of displayed items. The class returns an array of the requested rss data.
The code below creates an instance of the RSSFeed class named xo with an event listener waiting for a message that the processing of the rss feedhas been completed. On completion, the rssDataReady function is called which, in turn, calls the class function getResultSet which returns the array holding the requisite rss data. Three instances of the HTMLTextMultiline class are then used to display the data.
// import required classes import com.dtk.RSSFeed; import com.dtk.HTMLTextMultiline; // instance of RSSFeed class instructed to display 1st through 6th items in feed var xo:RSSFeed = new RSSFeed ( 'http://feeds.feedburner.com/TechCrunch', 0, 5 ); // event listener waiting for COMPLETE event & calling rssDataReady function xo.addEventListener( Event.COMPLETE, rssDataReady ); // function called on COMPLETE event function rssDataReady ( e:Event ):void { // init new array var feed:Array = []; // transfer returned rss results to new array feed = xo.getResultSet(); // init y position var yPos:uint = 10; // process display of items for ( var i:uint=0; i<feed.length; i++ ) { // sprite parent to each rss item var entry:Sprite = new Sprite(); addChild( entry ); // wrap title in HTML bold tags var rssTitle:String = '<b>' + feed[i].rssTitle + '</b>'; // convert to linked title by wrapping in HTML link tags & underline var linkedTitle:String = "<a href='" + feed[i].link + "'><u>" + rssTitle + "</u></a>"; // display linked title with instance of HTMLTextMultiline class var tt:HTMLTextMultiline = new HTMLTextMultiline( 340, 'Verdana', 12, 0x333333, 'LEFT', 0, linkedTitle ); tt.x = 10; tt.y = yPos; entry.addChild( tt ); // display publish date var dt:HTMLTextMultiline = new HTMLTextMultiline( 110, 'Verdana', 11, 0x333333, 'LEFT', 0, feed[i].published ); dt.x = 350; dt.y = yPos; entry.addChild( dt ); // increment y position by sprite height which is determined by textfield height yPos += entry.height; // display description which will automatically display any images included with another instance of HTMLTextMultiline class var ml:HTMLTextMultiline = new HTMLTextMultiline( 470, 'Verdana', 12, 0x333333, 'LEFT', 0, feed[i].description ); ml.x = 10; ml.y = yPos; entry.addChild( ml ); // get description textfield height (I reduced by 20) var entryHeight = entry.height - 20; // increment to starting y position of next item yPos += entryHeight; } } |
Download files: RSSFeed.zip (77)
If you found this post helpful please consider a Retweet. Thanks…
No Comments so far ↓
There are no comments yet...Kick things off by filling out the form below.