The art of loving music is learning to never be ashamed of your taste, learn to embrace and defend it to death. No matter how lame or kewl the stuff you have in your ear buds you have to pretend that you don’t care what others think of you … yes even while you get caught listening to Supertramp.
Now you can follow my latest tracks on the sidebar here to the right =>
Right underneath my adorable daughter Freyja which has been keeping my away from coding for the most part :) recently. Can’t wait to teach her to code!
So to back up my claim on not being ashamed of my music taste and attempt at getting familiar with actionscript I wrote a little package that will grap your rss feed from last.fm and dump it on your blog. This is the the kewl thing about actionscript it can snag stuff hosted else where and publish it on your website provided that you allow it in your crossdomain.xml file.
So here are some things I thought about actionscript until my college Adam showed me otherwise.
$ mxmlc MyAwesomeScript.as
and that will spit out the MyAwesomeScript.swf.
Now let’s take a look at my snippet
package {
import flash.display.Sprite;
import flash.events.*;
import flash.net.*;
import flash.external.ExternalInterface;
public class RecentTracks extends Sprite {
private var recentlyPlayed:XML;
private var rssUrl:String = "http://ws.audioscrobbler.com/2.0/user/bakdyr/recenttracks.rss";
public function RecentTracks() {
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, completeHandler);
var request:URLRequest = new URLRequest(rssUrl);
loader.load(request);
}
private function completeHandler(event:Event):void {
var outHtml:String;
var loader:URLLoader = URLLoader(event.target);
recentlyPlayed = new XML(loader.data);
outHtml = "<ul>\n";
for each (var title:XML in recentlyPlayed..item..title) {
var artist:String = title.toString().split(" – ")[0];
var song:String = title.toString().split(" – ")[1];
outHtml += "<li>" + song + "<br /><em>" + artist + "</em></li>\n";
}
outHtml += "</ul>\n";
ExternalInterface.call('Snitchmedia.recentTracks', outHtml);
}
}
}
Very simple little script that dials up the rss feed to last.fm and once it’s done it will call a javascript function that will handle outputting it on the page. Now this is very basic but I think an elegant solution to handle this sort of thing as I did not need to do any heroic mephisto, wordpress (or what ever the blog engine flavor of the month is) hacking and still able to add functionality to my blog. Obviously there is a lot of polishing to be done and I think I might make this a bit generic so it can be used to call in all sorts of third party fun stuff.
Now for completeness here is the javascript bit using jQuery.
var Snitchmedia = {};
Snitchmedia.recentTracks = function(playlist) {
$('#recent_tracks').html(playlist);
};
Sorry, comments are closed for this article.