Hello there, I’ve got an assignment for school in which I’m supposed to create an adobe air application which imports an rss feed, and use it to cause an event.
I’ve decided to create a weather application, using the following rss http://www.rssweather.com/wx/nl//amsterdam/rss.php
after importing the rss, a certain animation should play in reaction to this rss, if the weather is good a sun would play, if it would rain an another animation should play etc.
I’ve build most of the interface, but having some trouble importing the RSS, got some errors which I can’t work out since i got 0 experience with RSS.
Here is my as file code:
/* Main.as
** This is the main class of application <insert name here>
**
** Author:
** <name> <email>
**
** Copyright:
** Copyleft 2009, all wrongs reversed
*/
package {
// Import needed packages
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import com.adobe.utils.XMLUtil;
import com.adobe.xml.syndication.rss.Item20;
import com.adobe.xml.syndication.rss.RSS20;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
public class Main extends MovieClip {
// Variable declaration
private var loader:URLLoader;
private static const RSS_URL:String = "http://www.rssweather.com/wx/nl//amsterdam/rss.php";
// Build a constructor
public function Main(){
frame.exitButton.addEventListener(MouseEvent.CLICK, clickExit);
frame.minimizeButton.addEventListener(MouseEvent.CLICK, clickMinimize);
frame.maximizeButton.addEventListener(MouseEvent.CLICK, clickMaximize);
frame.dragButton.addEventListener(MouseEvent.MOUSE_DOWN, Beweeg);
textArea.text = "";
frame.refreshButton.addEventListener(MouseEvent.CLICK, onLoadPress);
}
//--------------------RSS--------------------------
//called when user presses the button to load feed
private function onLoadPress(e:MouseEvent):void {
trace("het bestand is gekoppeld!!!!!!");
loader = new URLLoader();
textArea.text += "Start load
";
//request pointing to feed
var request:URLRequest = new URLRequest(RSS_URL);
request.method = URLRequestMethod.GET;
//listen for when the data loads
loader.addEventListener(Event.COMPLETE, onDataLoad);
//listen for error events
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
//load the feed data
loader.load(request);
}
//called once the data has loaded from the feed
private function onDataLoad(e:Event):void {
//get the raw string data from the feed
var rawRSS:String = URLLoader(e.target).data;
textArea.text += "Load complete
";
textArea.text += "Parse RSS
";
//parse it as RSS
parseRSS(rawRSS);
}
//parses RSS 2.0 feed and prints out the feed titles into
//the text area
private function parseRSS(data:String):void {
textArea.text += "Check XML
";
//XMLSyndicationLibrary does not validate that the data contains valid
//XML, so you need to validate that the data is valid XML.
//We use the XMLUtil.isValidXML API from the corelib library.
if (XMLUtil.isValidXML(data) == false) {
writeOutput("<font color=\"#ff0000\">Feed does not contain valid XML.</font>");
return;
}else{
textArea.text += "Valid XML
";
}
//create RSS20 instance
var rss:RSS20 = new RSS20();
//parse the raw rss data
rss.parse(data);
//get all of the items within the feed
var items:Array=rss.items;
textArea.text += "Loop messages
";
textArea.text += "Got "+items.length+" messages
";
//loop through each item in the feed
for each (var item:Item20 in items) {
//print out the title of each item
writeOutput("<a href=\""+item.guid.id+"\"><b>"+item.title+"</b></a>")
writeOutput("<p>"+item.description+"</p>");
}
}
private function writeOutput(data:String):void {
textArea.htmlText+=data+"
";
}
private function onIOError(e:IOErrorEvent):void {
writeOutput("<font color=\"#ff0000\">IOError: " + e.text +"</font>");
}
private function onSecurityError(e:SecurityErrorEvent):void {
writeOutput("<font color=\"#ff0000\">SecurityError: " + e.text +"</font>");
}
//------------------menu------------------------------
//bij klikken op de neus, sluit het venster
public function clickExit(event:MouseEvent):void {
this.stage.nativeWindow.close();
}
//bij klikken op de - wang, minimize
public function clickMinimize(event:MouseEvent):void {
this.stage.nativeWindow.minimize();
}
//bij klikken op de + wang, maximize
public function clickMaximize(event:MouseEvent):void {
this.stage.nativeWindow.maximize();
frame.maximizeButton.removeEventListener(MouseEvent.CLICK, clickMaximize);
frame.maximizeButton.addEventListener(MouseEvent.CLICK, clickRestore);
}
//bij 2de click weer normale grote
public function clickRestore(event:MouseEvent):void {
this.stage.nativeWindow.restore();
frame.maximizeButton.removeEventListener(MouseEvent.CLICK, clickRestore);
frame.maximizeButton.addEventListener(MouseEvent.CLICK, clickMaximize);
}
public function Beweeg(event:MouseEvent):void {
this.stage.nativeWindow.startMove();
}
}
}//EOF
files downloadable here
http://stap.iam.hva.nl/~wullem01/weer_applicatie.zip
it gives the following errors:
1046: Type was not found or was not a compile-time constant: RSS20.
1046: Type was not found or was not a compile-time constant: Item20.
1120: Access of undefined property XMLUtil.
1180: Call to a possibly undefined method RSS20.
1172: Definition com.adobe.utils:XMLUtil could not be found.
1172: Definition com.adobe.xml.syndication.rss:Item20 could not be found
1172: Definition com.adobe.xml.syndication.rss:RSS20 could not be found.
I would really appreciate it if someone could help me with this, It´s my last assignment before I finish my year.
Thanks in advance.