Your open source for Development and Design

Flash/Actionscript wordpress RSS reader

Filed under: ActionScript,Flash — Tags: , , — Adi @ 2:16 pm January 21, 2009

I might come back and explain the code to this one in the future, but for now it is a basic example of how you can use Flash with dynamic content. Using and XML based RSS feed generated from word press we can use actionscript to import and interprete the tags into something we can use in Flash.

XML is a format used throughout coding languages and especialy popular with web based technology as it is a language all others can use.

I have left this example pretty basic so you can make edits without much knowledge of ActionScript, but if you have any questions leave a comment ;)

package {
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;
	import flash.net.*;
	import flash.system.*;

	public class rss extends MovieClip {

		public var xmldata:XML;
		public var titles:Array=new Array;

		public function rss(){ //constructor
			xmlimport();
			}

		public function xmlimport() {   /// the money shot
			xmldata=new XML;   //// create new xml feed
			var xmlURL:URLRequest=new URLRequest("http://www.open-source-web.com/feed/");   // set the url to the feed
			var xmlLoader:URLLoader=new URLLoader(xmlURL);       //// go get it
			xmlLoader.addEventListener(Event.COMPLETE,xmlLoaded);   /// on complete do something
			xmlLoader.addEventListener(IOErrorEvent.IO_ERROR,xmlLoadError);   /// else go here
		}
		public function xmlLoaded(event:Event) {   //// xml is loaded ok whahoo
			xmldata=XML(event.target.data); /// xml loaded ok
			trace("XML loaded successfully.");

			trace("first child - " + xmldata.children().length());   ///// trace the title for debug
			feedtest.text = xmldata.channel.title[0];    /// put title of feed in the box called feedtext

			var ex:int=10;  // position it
			var wi:int=100;

			for(var f:int=0; f < xmldata.channel.item.length(); f++){  // for each item int he feed process it
			trace(xmldata.channel.item[f].title);
			var titlebutton:titlebutt=new titlebutt;   //// make new product mc + add attributes
				titlebutton.x = ex;
				titlebutton.y = wi;
				titlebutton.description = xmldata.channel.item[f].description;
				titlebutton.link = xmldata.channel.item[f].link;
				titlebutton.addEventListener(MouseEvent.CLICK,clicked);   /// set for buttom mc clilcked
				titlebutton.addEventListener(MouseEvent.MOUSE_OVER,over);   //// get description on mouse over
				titlebutton.title.text = xmldata.channel.item[f].title;
				titles.push(titlebutton); /// add to array
				addChild(titlebutton);
				wi=wi+30;
			}
		}

		public function clicked(event:Event){    //// go to the article when clicked
		navigateToURL(new URLRequest(event["currentTarget"].link), "_blank");
	}

	public function over(event:Event){   //// load the description on mouse over
		descriptionbox.text = event["currentTarget"].description;
	}

		public function xmlLoadError(event:IOErrorEvent) {   /// check for error from loading xml file
			trace(event.text);
		}
	}
}

Download the Flash rss reader

Switch to our mobile site