“Be inspired, enjoy your work, keep learning and never forget to play.” — gskinner

Reading Zip files with Actionscript 3

Posted: September 24th, 2007 | Author: Tiago Bilou | Filed under: Actionscript3, Code, Tutorial | 6 Comments »

Last week, while developing an actionscript application, we had the need to read files stored inside a zip file. Our first approach was to use Zinc to deflate the zip file into a temporary directory.

Because some problems arouse with ZINC I took sometime to read about this AS3 Zip Library As it turns out it does a great job and reading and building zip files and it's really easy to use. Make sure you download and install the Library.

After playing around with this Library for a while I wanted to display some images I had inside the zip file. The issue was how to convert a ByteArry into a BitmapData. It took me a while to figure it out , but as it turns out it's really easy.


6 Comments on “Reading Zip files with Actionscript 3”

  1. 1 Help needed said at 10:42 am on April 9th, 2009:

    How to implement this fzip i am new to as not sure how to set it up if u can show me a woking example in a mxml it ll be great. going nuts setting up fzip… fairly new to as and not sure how to use classes and stuff. pls help

  2. 2 Alexander Cabezas said at 9:21 pm on July 6th, 2009:

    I’m using this library in air javascript application, so when i try to use this code i get the following error:

    TypeError: Value undefined is not a constructor. Cannot be used with new.

    My code is:

    var urlStream = new air.URLStream();
    urlStream.addEventListener(air.Event.COMPLETE, _completeHandler);

    urlStream.load( new air.URLRequest( url ) );

    function _completeHandler(event){
    air.Introspector.Console.log(event);
    var datastream = air.URLStream(event.target);
    var zipFile = new air.ZipFile(datastream);
    for(var i = 0; i <= zipFile.entries.length; i++) {
    var entry = zipFile.entries[i];
    air.Introspector.Console.log(entry.name);
    }
    }

  3. 3 Alexander Cabezas said at 9:42 pm on July 6th, 2009:

    Sorry, i’m new in air development with javascript.

    I replace:
    var zipFile = new air.ZipFile(datastream);
    ===================
    For this:
    var zipFile = new window.runtime.nochump.util.zip.ZipFile(datastream);

  4. 4 shine india said at 11:22 am on February 11th, 2010:

    Its useful! nice thanx for the code

  5. 5 mmbee said at 7:16 pm on February 25th, 2010:

    Great Job. My problem is resolved. I’m able to unzip the xml file and get the data. thank you so much.

  6. 6 gadgeteer said at 1:30 pm on July 20th, 2010:

    Could you use this library in a web based swf file to have the swf read all of the resources it needs (images,videos,xml) from a zip file? … better yet, could you implement a generic swf that when passed a zip file read an xml specification file (manifest.xml?) for which resource in the zip file is the actually flash object to load and run?


Leave a Reply