as3使用airxzip压缩和解压缩文件

时间:2012-09-03 20:23:20

标签: actionscript-3 flash actionscript zip unzip

我想使用airxzip,但我不知道如何下载源文件以及放置它的位置。

我很抱歉成为这样的新手。

感谢您提供的任何帮助。

以下是我尝试访问的zip / unzip as3代码的链接。

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

以下是“解压缩”的示例,但我不知道如何下载要导入的文件。

// 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();
        }
}

1 个答案:

答案 0 :(得分:8)

Flash Builder


1. Download the SWC File. airxzip

enter image description here


<强> 2. In your flash builder project make a {库{1}}

enter image description here enter image description here


<强> folder. and downloaded SWC files drag and drop or copy.

enter image description here


<强> 3. In your project mouse right click and Properties click.

enter image description here enter image description here



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

<强> Flash (below image Mac OS)

enter image description here


<强> 1. File-ActionScript Settings Click enter image description here enter image description here


<强> 2. Browse to SWC File icon Click. and downloaded your SWC File link.

enter image description here


<强> 3. publish setting, Target set a AIR2.5 or AIR 3.X ios or AIR 3.X Android. 这是一个示例代码。 simple_unzip

4. check out below my sample code. I tested.

从现在开始,可以查看示例代码。默认环境已经完成。

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();

  

Adob​​e SWC文件是预编译的Flash符号包   允许Flash或Flex开发人员分发的ActionScript代码   类和资产,或避免重新编译符号和代码   不要改变。