Paged Loading with XML-based Recordsets
Tuesday, February 13th, 2007One of the nicest things about Flash Remoting in Actionscript 2 is the pageable recordset functionality. This allows you to split the results of a large data set into chunks, or pages, that can be downloaded on an as-needed basis. This is a demonstration of how to use this paging functionality with XML-based web services. Specifically, I’ve created a sample application that uses the Flickr REST API (XML) to do a photo search.
Demo: Flickr Tag Search
Source: FlickrDemo.zip
Enter a tag in the search box, and hit ‘go’. The results are loaded in batches of 100, and they fill in as you scroll. As you can see, we know how many records are available even before they are all loaded. We are
I’ve used this feature on a number of projects that included Flash remoting, and it is truly amazing. When in paged loading mode, a recordset instance is like an array that doesn’t have all it’s slots filled in. If I am a movie clip representing a datagrid row that needs record at slot 537 and that record is not loaded yet, the recordset gives me a little message, “in progress”, instead of the actual data. The mx.remoting.Recordset class and it’s friends take care of managing the server requests needed to load the missing data. Then, I simply listen for model change events until I get the data I need. As the definition above states, the List-based v2 UI components all understand this data provider API and can auto-fill themselves on an as-needed basis. This makes it possible to create things like scrolling lists that have thousands of records.
There are times when I’ve needed this same kind of paged loading functionality, but I didn’t have access to Flash remoting. Instead, I needed to use an XML-based service that returned results based on GET method parameters that would either specify or range of records to return or simply a page number and the number of items per page. So, I have built a couple of classes that fetch data using XML and then use the built-in paging functionality provided with the mx.remoting code. This system has been set up in such a way that you can simply extend my XmlRecordsetService base class, implement a few key functions, and your result will be an instance of a class that extends mx.remoting.RecordSet. This recordset can be plugged in to any of the list-based components that come with Flash including the DataGrid that I have used in my demo.
Now, on to the code…





MTASC, the open-source Actionscript compiler, has become an essential part of my daily routine. I used it for a long time with custom built BAT files that would inject compiled code into my library SWF’s, but now I can do all of this with FlashDevelop. There are other editors out there, but FlashDevelop is my current IDE of choice, and it just so happens that it has a cute little feature I’ve not seen elsewhere. That feature is called “Quick MTASC Build”, and I use it all the time to build quick test SWF’s without ever having to open up the Flash authoring environment. I refer to these FLA-less SWF’s as MTASC Applets.