Flash example

Reading a zip in flash

The format zip library is cross platform, which means that it can be used in flash targets. This overcomes the problems of using zip files in flash applications when programming in Actionscript.

The usage is basically the same, only the data loading differs.

Here's an example assuming that we have the same "" as created here

static function main() 
    // Create a URLLoader, set its data format to binary, add a complete listener and start loading:
    var ul = new URLLoader();
    ul.dataFormat = URLLoaderDataFormat.BINARY;
    ul.addEventListener(Event.COMPLETE, onZipLoaded);
    ul.load(new URLRequest(''));        

static private function onZipLoaded(e:Event):Void 
    trace('Zip loaded!');
    // Grab the data as a ByteArray out of the
    var byteArray:ByteArray = cast(, URLLoader).data;
    // Convert the ByteArray into Bytes format
    var bytes:Bytes = Bytes.ofData(byteArray);    
    // Populate the BytesInput stream with our bytes
    var bytesInput = new BytesInput(bytes);
    // From here on exactly like usage on neko/cpp targets...
    var reader = new;
    var entries:List<> =;            
    var searchEntryFileName = "path/to/textfile.txt";
    for (entry in entries ) {
        if (entry.fileName == searchEntryFileName) {
            var bytes:Bytes =;
            var string = bytes.toString();
            trace(string); // <--- Traces "Hello zip!"

version #15558, modified 2012-10-20 03:18:14 by bradparks