A few people have expressed curiosity in it so I thought I’d run through how its done. At this stage its really very simple but I have plans to extend its operation to automate more of the running of it.
Macromedia first introduced the ability for the SWF format to parse XML data back in the days of Flash 5 (2000? 2001?). It was pretty basic was pretty shoddily implemented as well. It was never quite resolved whether it was an issue with the actual actionscript events or the Flash Player failing to parse these events (my money was on the latter) but suffice it to say, whilst it was great to be able to introduce another area of flexibility to SWF, it wasn’t until the release of Flash MX and the version 7 player that SWF/XML integration became a more reliable process.
It was around that time that Actionscript Guru, Sam Wan released his RSSDataFactory object which made coding the integration of RSS feeds very easy. He claims it only works with RSS 0.92 but it works fine with RSS 2.0 also.
So, I turned to this RSS object to handle the laborious work of processing the RSS. It was originally built to handle just one feed so I had a few tasks to make it operational for multiple feeds. I also had the thorny issue of the infamous Flash Sandbox to negotiate. More on that later.
Customising the RSSDataFactory is a doddle. First of all I simply inserted another keyframe and moved the DataFactory code to the second keyframe and applied a universal stop(); action to all keyframes. So, now I had two frames to play in I could put all my top level links in frame one and the parsed RSS feeds would display on frame two. Easy.
In frame one then I simply listed all the feeds I was going to be utilising as buttons and coded them appropriately.
Now you may notice at this stage that I’m not calling the feed directly. This is due to the pernicious influence of the Flash Sandbox. The Sandbox is a security measure. It doesn’t allow movies or scripts from servers on domains other than the one the SWF exists on to be accessed directly from the SWF. So what we have to do is build a sort of proxy – a script that _can_ access remote files and, as this proxy script exists on our domain, we can access anything it returns. Problem solved. Now you can see why calling remote XML files is pointless – nothing would be returned due to the Sandbox – so instead I call the proxy script. And because I have multiple feeds, I append a name/value pair (....php?feed=1) to each separate button. I can then detect these in my proxy script and hence return the desired script:
Now we turn our attention to this proxy script (which I called ‘antisandbox.php’). What we’re doing here is detecting the incoming value of the variable ‘feed’ fetching the appropriate RSS feed and opening it up for our SWF to process.
There are a few ways to do this, notably using readfile() but they are mostly (and again, notably readfile()) badly insecure. The way to securely get the feeds is to use (in PHP anyway) CURL. CURL opens a decent, protocoled connection to the remote RSS script. Its syntactically very like using a session in that you initialise it, use it then close it:
I should really have used switch to do the evaluation of the feed variable as its quicker. Probably will implement that soon.
So now we’ve got our data, we have to parse it in. Thankfully all this is done in Sam’s excellent Factory. All I had to do was pass it the value of the proxy script with the right name/value pair.
The last line of this script
rssObj.parseFeed(_root.theFeed, this, "receiveRSSObject");
calls the SWF variable I set in the previous frame that specified which value to send to the proxy script (and thus which RSS feed to fetch).
These are quite interesting:
In fame two I built a movieclip template. This template contains an empty dynamic text holder and an empty URL variable. When the RSS feed comes in, depending on how many posts each author specified their feeds help, each one of these posts would duplicate the movieclip and send the title of each post in the feed and the correct permanent link to these posts. It also spaces out each newly generated movieclip below the previously generated one.
My last problem was the ‘back’ button. Going back a frame in Flash doesn’t affect whats in the frame you’ve just left so I had to clear these newly generated movieclips, clear theFeed and reset the whole shebang everytime someone clicked the ‘back’ button.
Note I simply hide the ‘old’ buttons off stage – this speeds up regeneration if a user wants to revisit a certain feed in the same session.
And thats it for now. I will be extending this to make my life easier. For now, if I want to add a new feed I have to edit the FLA and ‘antisandbox.php’ which is a bit of a pain. What I hope to do is write a plug-in for WordPress that will create an XML file from a link category in the WordPress database architecture. I can then use this XML file to auto generate the feed list in frame 1. The second half of this plug in will drag these details from the database and execute them in ‘antisandbox.php’.
Recent Comments