Warning: Cannot modify header information - headers already sent by (output started at G:\wwwroot\flashlizi-riaidea\wwwroot\blog\wp-404-handler.php:1) in G:\wwwroot\flashlizi-riaidea\wwwroot\blog\wp-404-handler.php on line 2
RIAidea – Focus on Flash/Flex/AIR » Blog Archive » AS3 Library: ZipArchive 0.1 Release
Browse > Home > Flash CS3/AS3 > AS3 Library: ZipArchive 0.1 Release

| Subcribe via RSS

AS3 Library: ZipArchive 0.1 Release

三月 5th, 2008 | 1 views | Posted by flashlizi in Flash CS3/AS3

ZipArchive是一个Zip档案处理类,可读写各种zip格式文件。(update version 0.11)

基本介绍:
1)轻松创建或加载一个zip档案;
2)多种方式读取和删除zip档案中的文件;
3)支持中文文件名;
4)非常容易序列化一个zip档案,如有AIR、PHP等的支持就可以把生成的zip档案保存在本地或服务器上。

更新:此项目已更新至0.2版本,请大家到http://code.google.com/p/as3-ziparchive/去下载最新的源码和示例。
下载:源文件+API文档+示例
查看:API文档

读取zip文件可查看下载包中的example示例。保存zip文件部分可参考我以前发布的AirZip功能演示。

下面是下载包中的example示例的部分代码:

public class Example extends Sprite {
private var zip1:ZipArchive = new ZipArchive();
public function Example() {
//加载一个zip档案
zip1.load(“test.zip”);
zip1.addEventListener(ProgressEvent.PROGRESS, loading);
zip1.addEventListener(ZipEvent.ZIP_INIT, inited);
zip1.addEventListener(ZipEvent.ZIP_FAILED, failed);
zip1.addEventListener(IOErrorEvent.IO_ERROR, ioError);
}
private function inited(evt:ZipEvent):void {
zip1.removeEventListener(ProgressEvent.PROGRESS, loading);
zip1.removeEventListener(ZipEvent.ZIP_INIT, inited);
zip1.removeEventListener(ZipEvent.ZIP_FAILED, failed);
//添加ZIP_CONTENT_LOADED事件侦听器
zip1.addEventListener(ZipEvent.ZIP_CONTENT_LOADED, imgloaded);
trace(“原始zip文件内容\r”, zip1);
//读取zip1中的xml文件
var xmlFile:ZipFile = zip1.getFileByName(“sample.xml”);
var xml:XML = new XML(xmlFile.data);
trace(xml);
//根据字符串内容创建一个新的txt文件
var txtContent:String = “这是一个测试文本文件”;
zip1.addFileFromString(“测试.txt”, txtContent);
//trace(zip1.getFileByName(“测试.txt”).data);
//复制zip1中的girl.jpg为张曼玉.jpg
var zmy:ZipFile = zip1.getFileByName(“girl.jpg”);
zip1.addFileFromBytes(“张曼玉.jpg”, zmy.data);
//加载zip1中的新生成的图片文件的Bitmap对象
zip1.getBitmapByName(“张曼玉.jpg”);
//删除图片文件logo.gif
zip1.removeFileByName(“logo.gif”);
trace(“\r修改后的zip文件内容\r”, zip1);
}
private function imgloaded(evt:ZipEvent):void {
zip1.removeEventListener(ZipEvent.ZIP_CONTENT_LOADED, imgloaded);
var img:Bitmap = evt.content as Bitmap;
addChild(img);
}
private function loading(evt:ProgressEvent):void {
//trace(evt.currentTarget, evt.bytesLoaded, evt.bytesTotal);
}
private function failed(evt:ZipEvent):void {
//trace(evt.content);
}
private function ioError(evt:IOErrorEvent):void {
//trace(evt);
}
}

7 Responses to “AS3 Library: ZipArchive 0.1 Release”

  1. lanker Says:

    你好如果zip文件有密码怎么办?


  2. 旭旭 Says:

    如果ZIP里面的swf要加载外边的swf得怎么办!我好像加载不了
    要不把第二个也放进那个ZIP里面又得怎么写
    能不能说一下啊


  3. jacob Says:

    hi,有意向换工作吗?公司招聘as3高级程序员。加偶的QQ聊下。83538347。


  4. xx Says:

    收了 多谢


  5. ZIP (file format)在flash中的应用 « 晨风 Says:

    [...] 4,ZipArchive: http://www.riaidea.com/blog/archives/35.html [...]


  6. 修一 Says:

    请问ZipArchive有版权问题吗?
    如果用在商业项目怎么样?


  7. flashlizi Says:

    可以在商业项目中使用。


Leave a Reply