This project consists of two (2) files: a python script and an AS class file.
You use the python script to create a new XML file describing all your external files (XML, bitmap, video, etc.) by
... [More]
simply pointing it at the folder(s) containing those files.
Run the python script from the command line (or from an Ant script -- example will be forthcoming soon).
Example command line usage:
python cachebuilder.py build/images build/xml
This script will write out an XML file giving you all the information you need to preload all of these files with accurate information as to how far along you are -- in each folder you care about, if you choose to share that with the user!
Download it here:
http://flisp.googlecode.com/svn/trunk/cachebuilder.py
...and put it in your project's root folder, then open a terminal window and navigate to that same folder. Then invoke this script using "python cachebuilder.py" followed by the names of the folders you want it to scan for files.
So, for example, with the command line:
python cachebuilder.py build/jpeg build/swf
it might generate a file like:
python cachebuilder.py build
and it would generate a preloadcache.xml file like this:
Now the next step is to write an AS class that knows exactly how to parse this XML doc and sequentially load all the files while firing off a callback announcing (a) the name of the file you're currently loading, (b) the name of the folder you're currently loading, (b) the bytes you've already loaded of the current file, (c) the totalbytes of the current file, (d) the bytes you've loaded of the current folder, (e) the totalbytes of the current folder, (f) the bytes you've already loaded of the whole enchilada, and (g) the totalbytes of the whole enchilada.
I'm thinking it'll just make a nice associative array with these properties defined in it, and pass that along to any function you designate as the onLoadProgress handler.
so for the example right above, every time more data arrives as part of the load process, you'd fire off the equivalent of this:
yourhandlerfunction( { currentfile: "build/jpeg/photo1.jpg", currentfolder: "build", filebytesloaded: 73, filebytesneeded:500, folderbytesloaded:73, folderbytesneeded:2000, totalbytesloaded:73, totalbytesneeded:2000} );
so then the handler could just reach into that object and get its info. For example:
myhandlerfunction( info_object: Object ) {
var ratio:Number = info_object[ "totalbytesloaded" ] / info_object[ "totalbytestotal" ] ; progressbar.xscale = ratio 100;
} [Less]