Make fl.containers.UILoader Use Image Caching

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.


  1. Only works with sources that are String url’s
  2. Only works when loading bitmaps (not SWF’s)
  3. ByteArray’s are not supported (via loadBytes vs. setting source)
  4. I never remove the un-used Loaders
  5. I never remove the Bitmaps from cache


Here’s UILoader.  Also, I’ve included the fixed UIComponent as well (?) in case you actually want it to… you know, work.

One Reply to “Make fl.containers.UILoader Use Image Caching”

Comments are closed.