Search code examples
actionscript-3flashactionscriptzipunzip

as3 zip and unzip files using airxzip


I would like to use airxzip but I don't know how to download the source file and where to place it if I do.

I am sorry for being such a newbie at this.

Thanks for any help you can offer.

Below is the link to the zip/unzip as3 code I am trying to access.

http://flex.coltware.com/2010/05/01/as3-zip-unzip-lib-airxzip/

Below is a sample to "unzip" but again I don't know how to download the files for importing.

// ActionScript file
import com.coltware.airxzip.ZipEntry;
import com.coltware.airxzip.ZipError;
import com.coltware.airxzip.ZipFileReader;
import com.coltware.airxzip.*;

import flash.filesystem.File;
import flash.utils.ByteArray;

use namespace zip_internal;

public function unzip_init(filename:String):ZipFileReader{
        var reader:ZipFileReader = new ZipFileReader();
        var file:File = File.desktopDirectory.resolvePath(filename);
        reader.open(file);
        return reader;
}

public function unzip_sample1():void{
        var reader:ZipFileReader = unzip_init("new_airxzip.zip");
        var list:Array = reader.getEntries();

        for each(var entry:ZipEntry in list){

                if(entry.isDirectory()){
                        log.debug("DIR  --->" + entry.getFilename());
                }
                else{
                        log.debug("FILE --->" + entry.getFilename() + "(" + entry.getCompressRate() + ")");
                }
        }
}

public function unzip_sample2():void{
        var reader:ZipFileReader = unzip_init("new_airxzip.zip");
        var list:Array = reader.getEntries();

        for each(var entry:ZipEntry in list){
                if(!entry.isDirectory()){
                        if(entry.getFilename() == "sample.txt"){
                                var bytes:ByteArray = reader.unzip(entry);
                                log.debug("sample.txt : " + bytes);
                        }
                }
        }
}

public function unzip_sample3():void{
        var reader:ZipFileReader = unzip_init("crypto_airxzip.zip");
        reader.setPassword("pass");
        var list:Array = reader.getEntries();

        for each(var entry:ZipEntry in list){
                if(!entry.isDirectory()){
                        if(entry.getFilename() == "sample.txt"){
                                try{
                                        var bytes:ByteArray = reader.unzip(entry);
                                        log.debug("sample.txt : " + bytes);
                                }
                                catch(e:ZipError){
                                        log.warn(entry.getFilename() + ":" + e.message);
                                }
                        }
                }
        }
}
public function unzip_sample4():void{
        var reader:ZipFileReader = unzip_init("abc.zip");
        var list:Array = reader.getEntries();
        for each(var entry:ZipEntry in list){
                entry.dumpLogInfo();
        }
}

Solution

  • Flash Builder


    1. Download the SWC File. airxzip

    enter image description here


    2. In your flash builder project make alibsfolder. and downloaded SWC files drag and drop or copy.

    enter image description here enter image description here


    3. In your project mouse right click and Properties click.

    enter image description here


    4. Actionscript Build Path - Library Path - Add SWC Folder click and input a libs

    enter image description here enter image description here



    Flash (below image Mac OS)

    1. File-ActionScript Settings Click

    enter image description here


    2. Browse to SWC File icon Click. and downloaded your SWC File link. enter image description here enter image description here


    3. publish setting, Target set a AIR2.5 or AIR 3.X ios or AIR 3.X Android.

    enter image description here


    4. check out below my sample code. I tested. here is a sample code. simple_unzip

    import com.coltware.airxzip.ZipEntry;
    import com.coltware.airxzip.ZipError;
    import com.coltware.airxzip.ZipFileReader;
    import com.coltware.airxzip.*;
    
    import flash.filesystem.File;
    import flash.utils.ByteArray;
    import flash.net.FileReference;
    import flash.net.FileFilter;
    
    var file:File;
    var fileReference:FileReference;
    var fileFilter:FileFilter;
    
    function unzip_init():void{
    
        fileFilter = new FileFilter("selected your zip file.", "*.zip; .gz2; .bz2;");
        file = new File();
        file.browseForOpen("\Users", [fileFilter]);
        file.addEventListener(Event.SELECT, onSelectedFile);
    }
    
    function onSelectedFile(e:Event):void
    {
        var reader:ZipFileReader = new ZipFileReader();
        reader.open(file);
    
        var list:Array = reader.getEntries();
    
            for each(var entry:ZipEntry in list){
    
                    if(entry.isDirectory()){
                            trace("DIR  --->" + entry.getFilename());
                    }
                    else{
                            trace("FILE --->" + entry.getFilename() + "(" + entry.getCompressRate() + ")");
                    }
            }
    }
    
    unzip_init();
    

    from now, possible check out the sample code. default Environment has been completed.

    What's the SWC?

    an Adobe SWC file is a package of precompiled Flash symbols and ActionScript code that allows a Flash or Flex developer to distribute classes and assets, or to avoid recompiling symbols and code that will not change.