Super Simple WordPress To Flash Feed Reader (By Author, Category, Etc) — Source Files

SOURCE FILES HERE! (AS3, and AS2)

Short Summary:
Wordpress feed readers + Flash are a popular things to do (ever since the Macromedia weblogs). I had a nice and tidy widget version programmed way back for my old site, as well as played with the same model in Flex. Although it no longer displays because the feed is long dead (RIP early roots of social media), sorting them by category/author, then syndicating to Flash when you do have the feed URL (RSS or atom), is a simple endeavor once you get all the php query vars. Searching on the WordPress site eventually got me what I needed.
This is similar to a twitter feed reader (tutorial here)… but the appeal to this was that you can pull in more text, don’t need a .php mediator, don’t have the “100 pings-per-hour” restriction, and it’s hosted on your own server… It offered a lot more flexibility. Both go well hand in hand.
The amazing thing about WordPress is that it’s so extendible, and any part of it can easily be syndicated/pulled in/plugged into Flash (and vice versa). One of my next “dream ideas” for weekend meddling would be to make a full on flash theme for WordPress.

This applies to non-Flash syndicators as well. You see them everywhere, and here’s how you usually do it (WordPress.org is packed with approaches to this – search their forums).

Query Vars & ID’s:

For starters you use one (or more) of the Query Vars, such as username (author_name), or category name (category_name) , and pass that request from Flash to WordPress.
Here’s a list.
THEN parse it accordingly.
Alternatively you can go with ID’s (numeric). Such as “author=1”.

There are a number of ways to get those values, basically you can get as advanced as you like — write some php that parses all of everything and then make a call from flash to that file, etc…
BUT for this example, instead of getting crazy handsome, you can just copy the names of the query vars in the URL when you rollover categories/author in the “Posts” section…


Examples would be…

author=1
author_name=admin
category_name=resources

I like simple.

Flash:

Make a Dynamic text field and call it:

txt_feed

As well as two movieclips to serve as page up/down buttons.
Name them:

btn_down
btn_up

CODE:

Actionscript 3.0 Version (DOWNLOAD SOURCE CS5.5, DOWNLOAD SOURCE CS4)…

import flash.events.Event;

//EXAMPLE:
//author=1
//author_name=admin
//category_name=resources
var str_feed:String = "http://nathalielawhead.com/candybox/?feed=rss2&";
var str_sortby:String = "category_name=resources";
var str_url:String = str_feed + str_sortby;

//arrays
var arr_title:Array = new Array();
var arr_date:Array = new Array();
var arr_body:Array = new Array();
var arr_link:Array = new Array();

//xml
var feedXML:XML;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, getFeed);
loader.load(new URLRequest(str_url));
txt_feed.text = "Slowding";

function getFeed(evt:Event)
{
	feedXML = new XML(loader.data);
	//this is everything. it's looped through and parsed bellow.
	var feedXMLitem:Object = feedXML..item;
	txt_feed.text = "";
	//parse it...
	for (var i:Number = 0; i<feedxmlitem .length(); ++i)
	{
		arr_title.push(feedXMLitem.title[i]);
		arr_date.push(feedXMLitem.pubDate[i]);
		arr_body.push(feedXMLitem.description[i]);
		arr_link.push(feedXMLitem.link[i]);
		//populate + format
		txt_feed.htmlText +=
		"< font color = ' #999999 ' >" 
		+ arr_title[i]+
		"\n"
		+arr_date[i]+
		"' \n"
		+arr_body[i]+
		"< font color = ' #0066FF ' >< a href='" 
		+ arr_link[i]+
		"'target= '_blank ' >\n READ MORE< / font > \n\n";
	}
}

// scroll up/down buttons
function scroll_downe(_event:Event){
	txt_feed.scrollV +=  1;
}
function scroll_upe(_event:Event){
	txt_feed.scrollV -=  1;
}
function scroll_field(_event:MouseEvent)
{
	if(_event.currentTarget.name == "btn_down"){
		_event.currentTarget.addEventListener(Event.ENTER_FRAME,scroll_downe);
	}
	if(_event.currentTarget.name == "btn_up"){
		_event.currentTarget.addEventListener(Event.ENTER_FRAME,scroll_upe);
	}
}
function scroll_stop(_event:MouseEvent){
	_event.currentTarget.removeEventListener(Event.ENTER_FRAME,scroll_downe);
	_event.currentTarget.removeEventListener(Event.ENTER_FRAME,scroll_upe);
}
btn_down.addEventListener(MouseEvent.MOUSE_DOWN,scroll_field);
btn_up.addEventListener(MouseEvent.MOUSE_DOWN,scroll_field);
btn_down.addEventListener(MouseEvent.MOUSE_UP,scroll_stop);
btn_up.addEventListener(MouseEvent.MOUSE_UP,scroll_stop);

End result:

[swfobj src=”http://nathalielawhead.com/sourcefiles/Wordpress_To_Flash_Authorfeed/authorfeed_3.0.swf” height=”280″ width=”291″]

Naturally you can get a lot more elaborate with the approach. The next obvious step would be to incorporate the ability to display images, turn it into a class… or just a full frontal wordpress theme!

But… It’s a good starting point.