Image Cache
Big Spaceship has another fun toy for you to play with. Our very own ImageCache class.
The idea behind the ImageCache is to load an image one time and then never again. Once loaded, store its BitmapData in an invisible movieclip, where it can be retrieved forever (memory permitting, of course). The BitmapData for said image is availible and accessible via its file path.
Play with it here.
Download it here.
In the example I posted above, I load each image one time. then I manipulate the bitmap data to create a mini-photogallery w/ dynamically resized bitmapdata thumbnails (using a simple Matrix to draw the thumbnails smaller).
The end result? Smoother photo galleries and downloads pages - we don’t need to wait until some load animation finishes every time a new image is called. We don’t even need to have a movieclip to load the image into. The asset we need is independant of timeline, scope and the browser cache. Oh yeah, and its much less code to deal with.
The best practical example of this is on the Underworld: Evolution web site’s photo gallery. The cache loads in the thumbnails first. When a thumbnail is clicked, if the image hasn’t been loaded it displays the preloader. If it has been loaded (or once the preloader finishes), the bar on the bottom slides up and as it reaches the top, we call one simple function and viola! Image appears. No need to even set visibility on the movieclip - just something as simple as this:
ImageCache.getInstance().retrieve( "path/to/image.jpg", myClipToDrawTo, "someID");




