Jump to content
Search Community

Cache URL's and Content?

ghassett test
Moderator Tag

Recommended Posts

Hello, I am using LoaderMax to load assets from a web server when my AS3/AIR game starts. Assets might be PNG files (using ImageLoader) or SWF's (using SWFLoader). I would like to cache the content in persistent storage -- since I am using AIR, this would be mean storing the cache in the computer's file system or the mobile device's application storage area, so that the next time my game is run, I do not have to reach out to the server and re-download the assets. I could use code like the following:

 

var file:File = File.applicationStorageDirectory.resolvePath ("test_cache_as3");

 

var fileStream:FileStream = new FileStream();

fileStream.open(file, FileMode.WRITE);

fileStream.writeObject(... my image/SWF ...);

 

But then I need to figure out how to serialize images and SWF's -- which doesn't appear to be an obvious thing to do. I tried with images, by calling

 

registerClassAlias ("Bitmap", Bitmap);

registerClassAlias ("BitmapData", BitmapData);

registerClassAlias ("Transform", Transform);

 

and then storing Bitmap's in a Dictionary keyed by their URL... reading the images back in caused headaches with the bitmap's BitmapData member.

 

Any advice or suggestions? This seems like it might be a common need (cacheing the results of URL fetches), so I feel like I am missing something obvious.

 

Thanks so much for your help!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...