Archive for the ‘Actionscript’ Category

Paged Loading with XML-based Recordsets

Tuesday, February 13th, 2007

One 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…

(more…)

Unexpected Results - Interpolating Sine

Thursday, January 18th, 2007

interpol_sine_th.gif

Demo: Interpolating Points on a Sine Curve
Source: interpolate_sine.zip

A recent post on the gotoAndPlay.net flashlist asked about charting the sine wave in flash using the drawing API. The problem with the drawing API is that the quadratic bezier curveTo functions don’t make for the smoothest curves without a little trickery.

Patrick Mineault has a great piece on his blog about piecewise cubic beziers. Using his code, we can interpolate between the points on a sine curve quite smoothly. I thought his demo was quite nice, so I download his source, hacked it a bit, and came up with this demo.

Yes, it makes a nice smooth curve, if that’s what you’re after, but the fun starts when you start playing with the controls. A good place to start is by setting the wavelength to 2 while increasing the overshoot. Once the wavelength gets below 4 pixels, the cubic bezier interpolation no longer has enough points to interpolate the high frequency wave accurately. Increasing the overshoot factor creates some unexpectedly fun curls. Altering the number of points plotted gives us even more variation.

Screenshot 1

Screenshot 2

Screenshot 3

Screenshot 4

Target-based tweening with FTween

Friday, November 24th, 2006

FTween is a simple tweening utility designed to fill a need not met by the Penner family of time-based tweening solutions. The problem case is one where a target is constantly moving and/or changing at unexpected times. The Penner equations rely on the assumption that a tween will last for a known length of time, but it is often the case that I simply want a smooth transition from one state to another. Tweening content for smooth scrolling and animating a tree menu are two common examples where time-based tweening can have stuttering or less than desirable result. When animating a sprite in such as way that it follows a moving target, Penner tweens don’t work at all.

(more…)

MTASC Applets

Wednesday, November 8th, 2006

quickbuild.jpgMTASC, 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.

(more…)

Smooth Image Resizing

Monday, October 30th, 2006

Much has been written about smoothing dynamically loaded bitmaps in Flash 8. But, just in case you missed it, here’s the short version: Flash 8 allows you to smooth dynamically loaded images such as JPG’s at runtime by taking a snapshot of the image using BitmapData and redrawing it on to a MovieClip with smoothing applied..

It’s one of those things you may never have realized you were missing until now.

(more…)