I’m creating an RSS parser based off of some code I have seen online, and am writing a new RSS parser based off of it.
The RSS parser that was online was for YouTube, and it worked fine, but when I wanted to add multiple feeds to it, it just went to hell.
So I am having some problems, and hopefully some of you can help me with them.
This is my code thus far:
Main File: RSS
package
{
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.SimpleButton;
import flash.text.*;
import flash.events.*;
import flash.net.*;
import flash.accessibility.Accessibility;
import ui.*;
public class RSS extends Sprite
{
private var _input_URL : String;
private var _GetFeed : GetFeed;
private var urlInput : TextField;
private var urlArray : Array = new Array();
public function RSS()
{
// Draw Submit Button
var simpleButton : SimpleButton = new SimpleButton();
var submitButtonUp : Shape = new Shape();
submitButtonUp.graphics.lineStyle(1, 0xFFFFFF, 1);
submitButtonUp.graphics.beginFill(0x000066, .5)
submitButtonUp.graphics.drawRoundRect(400, 50, 100, 15, 10);
submitButtonUp.graphics.endFill();
simpleButton.upState = submitButtonUp;
var submitButtonOver : Shape = new Shape();
submitButtonOver.graphics.lineStyle(1, 0xFFFFFF, 1);
submitButtonOver.graphics.beginFill(0x2222AA, .5)
submitButtonOver.graphics.drawRoundRect(400, 50, 100, 15, 10);
submitButtonOver.graphics.endFill();
simpleButton.overState = submitButtonOver;
var submitButtonDown : Shape = new Shape();
submitButtonDown.graphics.lineStyle(1, 0xFFFFFF, 1);
submitButtonDown.graphics.beginFill(0xAAAAFF, .5)
submitButtonDown.graphics.drawRoundRect(400, 50, 100, 15, 10);
submitButtonDown.graphics.endFill();
simpleButton.downState = submitButtonDown;
simpleButton.hitTestState = submitButtonUp;
simpleButton.addEventListener(MouseEvent.CLICK, onMouseClick)
addChild(simpleButton);
// Text to notify the user to type in the URL feed in the text input box
var urlInputLogo : TextField = new TextField();
urlInputLogo.x = 400;
urlInputLogo.y = 0;
urlInputLogo.width = 250;
urlInputLogo.height = 20;
urlInputLogo.text = "Type Feed URLS Here";
addChild(urlInputLogo);
// Text formatting
var urlInputStyle : TextFormat = new TextFormat();
urlInputStyle.font = "Verdana"
urlInputStyle.size = 6;
urlInputStyle.bold = true;
urlInputStyle.color = 0x0000AA;
// User types in the URLs they have the RSS feeds to be read
urlInput = new TextField();
urlInput.type = TextFieldType.INPUT;
urlInput.border = true;
urlInput.background = true;
urlInput.x = 400;
urlInput.y = 20;
urlInput.width = 200;
urlInput.height = 13;
urlInput.defaultTextFormat = urlInputStyle;
urlInput.addEventListener(KeyboardEvent.KEY_UP, onurlInput);
urlInput.text = "";
addChild(urlInput);
} // End RSS()
private function onurlInput(e:KeyboardEvent) : void
{
// If Enter Key Is Pressed
if(e.keyCode == 13)
{
// Push the URL typed into the Array that holds the URLS
urlArray.push(urlInput.getLineText(0));
// Clear the text field to accept more data from user
urlInput.replaceText(0,512,"");
// TO DO:
// Display the typed in URLS on the side of the screen so that
// the user can check if they typed in the URL correctly before
// submitting it. Also provide a "Clear" button to erase all the URLS
}
}
private function onMouseClick(e:MouseEvent) : void
{
// Passing the Array of URLS to the GetFeed class
_GetFeed : new GetFeed(urlArray);
}
} // End Class
} // End Package
GetFeed Class File
package ui
{
import flash.display.Sprite;
import flash.net.*;
import ui.*;
import flash.display.Loader;
import flash.text.TextField;
import flash.events.Event;
import flash.events.EventDispatcher;
// Create Class For XML
public class GetFeed extends EventDispatcher
{
// Variables
private var isProfile : Boolean;
private var isImages : Boolean;
private var isVideos : Boolean;
private var xmlLoader : URLLoader
private var xmlData : Array = new Array();
private var _url : String;
//
public function GetFeed(urlArray : Array)
{
// TO DO:
// Cycle Through Each URL Using the Array
xmlLoader = new URLLoader( new URLRequest(urlArray[0]));
xmlLoader.addEventListener(Event.COMPLETE, onxmlLoaderComplete);
} // End GetFeed()
private function onxmlLoaderComplete(e:Event):void
{
for each(var i : XML in new XML(e.target.data))
{
// Store each XML data set in the xmlData array
xmlData.push(i);
removeEventListener(Event.COMPLETE, onxmlLoaderComplete);
}
} // End onxmlLoaderComplete()
} // End Class
} // End Package
The questions are:
What is the best way to handle multiple RSS feeds, and am I on the right track?
I wish to create thumbnails for all the feeds, and grab the thumbnail information from each feed, yet different websites have different ways of labeling a “thumbnail”. For example, YouTube uses: <media:thumbnail>, Stickam uses: <small> (for a small picture, the thumbnail is even smaller), Jaiku uses: <jaiku:user nick=“JMowery” first_name=“James” last_name=“Mowery” avatar=“http://jaiku.com/image/1/avatar_82301_t.jpg” url=“http://JMowery.jaiku.com” />.
It’s just madness.
Yet somehow applications like Bloglines and Google Reader have no trouble taking in all kinds of feeds.
So, how do I go about handling multiple feeds from XML files that are more than likely different?
How do I go about finding the thumbnails for every individual item even if they are not formatted the same.
I want to in the end store all the XML data in a single array, and then pass the XML data into another class
which is to create the thumbnails and gather the images and descriptions and such.
So anyone have any tips/advice/help or anything that can help as to how to manage multiple feeds.
I want to in the end create the application so that the user can type in any RSS feed into a text box, and then submit it,
then the application goes and grabs that data and has it all there for easy access, think of it like a social community portal,
where everyone can get their friends RSS feeds and news and images and media and all that all in one spot.
I also need to somehow store all the data the user types in to have it saved so that when the user comes back at a later time, they can have access to their friends. I will probably just create a way to input a user name and then when the person types in their user name it will load the data somehow.
Any advice on learning how to store data on a server, and retrieve data on a server would be a great help for the future.
So yeah, I appreciate any help.
EDIT: BTW, I am sorry if my code is messy or makes all of you experts out there want to cry at how pathetic it is, hehe, I’m extremely new to all of this and this is a serious project at which I’m motivated on completing.