This is not code I’m proud of, nor have I thoroughly tested it. Â However, I know SOMEONE out there will need this, so here it is. Â Keep in mind, she leaks memory like a seive, but for a slideshow that shows to the user for 30 seconds, who cares. Â If you’re bored, you’re welcome to fix/mod/improve/re-write.
Client was mentioning that a slideshow I created for them was hitting the server each time requesting an image. Â Rather than go through the lengthy, and sometimes subjective process of describing why the browser cache can fail to work with Flash Player, I instead just made the images cache in RAM on the client side once downloaded.
I tried to integrate Ely’s SuperImage code (since all but 1 class is pure ActionScript and not Flex related), and in retrospect, I think I got it working. Â My 2nd approach was to just create a simple local cache, and that worked.
Basically, once the image is downloaded, I make a Bitmap copy and store in a Dictionary. Â When you load a new image, I check to see if I have the image cached already.
- Only works with sources that are String url’s
- Only works when loading bitmaps (not SWF’s)
- ByteArray’s are not supported (via loadBytes vs. setting source)
- I never remove the un-used Loaders
- I never remove the Bitmaps from cache