Last saturday I developed an ActionScript 3 RSS reader for my WordPress blog feed. It reads the posts from my blog divide them into categories and then populate each category with the thumb of the posts.
It’s an handy tool as it gives a quick glimpse of what I’ve been doing lately and doesn’t make you browse the whole history of my blog just to see an experiment.
Source
My first problem was to first recover how many categories there were and then populate them.
Hard coding the categories in fact would have been a little bit awkward for the main purpose of it (being completely automatic) and also I didn’t want to include the category free for all which is the category for non-experiment-related posts. I came up with this code:
private function createCategories():void { for each (var cat:XML in _items) { if (_categories.length > 0) { if (_categories.filter(checkCat) == false) { if (cat.category[0]!="free for all") { var cv:CategoryViewer=new CategoryViewer(cat); _categories.push(cv); } } } else { if (cat.category[0]!="free for all") { var firstCv:CategoryViewer=new CategoryViewer(cat); _categories.push(firstCv); } } } function checkCat(element:*,index:int,arr:Array):Boolean { if (element.catTitle == cat.category[0].text() && cat.category[0]!="free for all") { return true; } else { return false; } } populateCategories(); }
This basically says:
for each post in the blog check if the post has been already inserted in the _categories array (using the Array method filter with a callback function), if not be sure it is not “free for all”.
Then make a new categoryViewer object passing to it the post (cat) and finally push the categoryViewer into the _categories array.
Note that I’m checking the category title (catTitle) against the first element of the post.category node. So if I have a post with several categories I’ve to be sure that the first category I set in wordPress is the one I want.
In the constructor of the category class I will have:
public function CategoryViewer(cat:XML):void { catTitle=cat.category[0].text(); // and so on... }
After creating the categories populate them:
private function populateCategories():void { for each (var item:XML in _items) { _categories.filter(checkTitle); } function checkTitle(element:*,index:int,arr:Array):Boolean { if (item.category[0]==arr[index].catTitle && item.category[0]!="free for all") { arr[index].posts.push(item); return true; } else { return false; } } _categories.forEach(positionElement); function positionElement(element:*,index:int,arr:Array) { element.onComplete(); if (index>0) { distance+=arr[index-1].posts.length*80; if(distance<arr[index-1]._tb.width+arr[index-1].x)></arr[index-1]._tb.width+arr[index-1].x)> element.x=distance+arr[index-1]._tb.width-30; } else { element.x=distance; } } else { element.x=0; } addChild(element); } }
With the same principle this time for each post run through each category, if the name is the same it push the post into the respective categoryViewer posts array.
If this is any clear and needs corrections or you just liked it as it is, just let me know!

I am quite lost… Do you have the open source as an examples?