Some assets, especially JSON and XML files, can take up quite a lot of disk space. That can increase the install size of an app or game significantly.
Fortunately, though, many of those assets also compress very well when zipped – let's exploit that! With this extension, you can compress individual assets as zip-files and let them be decompressed by the AssetManager.
First, use a ZIP-tool of your choice to compress the relevant assets. Each zip file must contain one (and only one!) asset. The file name of the zip file is actually not relevant – the AssetManager will only look at the filename found inside the zip-file. Nevertheless, I recommend the following name scheme so that you easily see what's inside:
data.json => data.json.zip font.xml => font.xml.zip
To “install” this extension in your game, simply download the ZipLoader class from the Gist-link above and copy it to your game project. Furthermore, you need a copy of the FZip library. Download the swc library from here and add it to your project, as well.
Using the class is really easy: you simply assign a new ZipLoader instance to the AssetManager's dataLoader
property and, bam, it will unzip files automatically and transparently!
// instantiate the standard AssetManager var assets:AssetManager = new AssetManager(); // assign the "ZipLoader" assets.dataLoader = new ZipLoader();
When that's done, you use your AssetManager just like before, both for zipped and unzipped files.
assets.enqueue(appDir.resolvePath("assets/font.png")); assets.enqueue(appDir.resolvePath("assets/font.xml.zip")); assets.loadQueue(onComplete);
Happy zipping!
%gist(6c9874fb2c38c8376554c51f47b91777)%
Feel free to edit this part of the page if you want to add information that's lacking in the above description.
Questions are better asked in the forum, though.