AS3 打包ZIP范例
作者:jack 日期:2010-01-31
AS3 打包 ZIP 范例
Flex Builder 3 下编译通过
编译成 AIR
程序代码
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
width="420"
height="238">
<mx:TitleWindow layout="absolute"
left="43"
top="22"
bottom="27"
right="43"
title="MP3打包程序"
fontSize="12">
<mx:TextInput x="10"
y="10"
width="190"
height="22"
id="fileName"/>
<mx:Button x="208"
y="10"
label="浏览"
width="60"
fontSize="12"
fontFamily="Arial"
fontWeight="normal"
height="22"
click="browseFile(event);"
id="browse"/>
<mx:Button x="218"
y="61"
label="打包"
fontSize="12"
fontFamily="Arial"
fontWeight="normal"
click="zipFile(event);"
id="pack"/>
<mx:Text x="10"
y="40"
text="请选择文件!"
width="190"
color="#CF1C1C"
fontSize="12"
fontFamily="Arial"
height="95"
id="tip"/>
</mx:TitleWindow>
<mx:Script>
<![CDATA[
import deng.fzip.FZipFile;
import deng.fzip.FZipErrorEvent;
import deng.fzip.FZip;
private var mp3file:File=new File();
private var mp3filefilter:FileFilter=new FileFilter("mp3", "*");
private var mp3Stream:FileStream=new FileStream();
private var mp3ByteArray:ByteArray=new ByteArray();
private var selected:Boolean=false;
private var zipName:String;
//
private var zipfile:File;
private var zipStream:FileStream;
//
private var zipMp3:FZip;
//
private function browseFile(evt:Event):void
{
mp3file.browseForOpen("mp3文件", [mp3filefilter]);
mp3file.addEventListener(Event.Select, fileSelectHandle);
mp3file.addEventListener(Event.CANCEL, selectCancel);
}
//
private function selectCancel(evt:Event):void
{
tip.text="没有选择MP3文件。";
selected=false
}
//
private function fileSelectHandle(evt:Event):void
{
tip.text="选择了文件:" + mp3file.name;
fileName.text=mp3file.nativePath;
selected=true;
}
//
private function zipFile(evt:Event):void
{
if (selected)
{
mp3Stream.open(mp3file, FileMode.READ);
mp3Stream.readBytes(mp3ByteArray);
mp3Stream.close();
zipMp3=new FZip();
tip.text="文件压缩中.....";
zipMp3.addFileAt(0,mp3file.name, mp3ByteArray);
zipMp3.close();
mp3ziped();
}
else
{
tip.text="你还没有选择要打开的文件。";
fileName.text="";
}
}
private function mp3ziped():void
{
zipfile=File.documentsDirectory;
zipfile.browseForSave("保存为文件");
zipfile.addEventListener(Event.Select, savezip);
}
private function savezip(evt:Event):void
{
var zipStream:FileStream=new FileStream();
var zipByteArray:ByteArray=new ByteArray();
var file:File=new File(File.desktopDirectory.nativePath);
file=file.resolvePath("temp.abc");
tip.text="正写入文件";
zipMp3.serialize(zipByteArray);
zipStream.open(file, FileMode.WRITE);
zipStream.writeBytes(zipByteArray);
zipStream.close();
file.moveTo(zipfile, true);
tip.text="已经生成文件:" + zipfile.nativePath;
fileName.text="";
}
private function ioerr(evt:IOErrorEvent):void
{
tip.text="错误:" + evt.type;
}
]]>
</mx:Script>
</mx:WindowedApplication>
FZip 类下载:
http://codeazur.com.br/lab/fzip/
Flex Builder 3 下编译通过
编译成 AIR
程序代码<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
width="420"
height="238">
<mx:TitleWindow layout="absolute"
left="43"
top="22"
bottom="27"
right="43"
title="MP3打包程序"
fontSize="12">
<mx:TextInput x="10"
y="10"
width="190"
height="22"
id="fileName"/>
<mx:Button x="208"
y="10"
label="浏览"
width="60"
fontSize="12"
fontFamily="Arial"
fontWeight="normal"
height="22"
click="browseFile(event);"
id="browse"/>
<mx:Button x="218"
y="61"
label="打包"
fontSize="12"
fontFamily="Arial"
fontWeight="normal"
click="zipFile(event);"
id="pack"/>
<mx:Text x="10"
y="40"
text="请选择文件!"
width="190"
color="#CF1C1C"
fontSize="12"
fontFamily="Arial"
height="95"
id="tip"/>
</mx:TitleWindow>
<mx:Script>
<![CDATA[
import deng.fzip.FZipFile;
import deng.fzip.FZipErrorEvent;
import deng.fzip.FZip;
private var mp3file:File=new File();
private var mp3filefilter:FileFilter=new FileFilter("mp3", "*");
private var mp3Stream:FileStream=new FileStream();
private var mp3ByteArray:ByteArray=new ByteArray();
private var selected:Boolean=false;
private var zipName:String;
//
private var zipfile:File;
private var zipStream:FileStream;
//
private var zipMp3:FZip;
//
private function browseFile(evt:Event):void
{
mp3file.browseForOpen("mp3文件", [mp3filefilter]);
mp3file.addEventListener(Event.Select, fileSelectHandle);
mp3file.addEventListener(Event.CANCEL, selectCancel);
}
//
private function selectCancel(evt:Event):void
{
tip.text="没有选择MP3文件。";
selected=false
}
//
private function fileSelectHandle(evt:Event):void
{
tip.text="选择了文件:" + mp3file.name;
fileName.text=mp3file.nativePath;
selected=true;
}
//
private function zipFile(evt:Event):void
{
if (selected)
{
mp3Stream.open(mp3file, FileMode.READ);
mp3Stream.readBytes(mp3ByteArray);
mp3Stream.close();
zipMp3=new FZip();
tip.text="文件压缩中.....";
zipMp3.addFileAt(0,mp3file.name, mp3ByteArray);
zipMp3.close();
mp3ziped();
}
else
{
tip.text="你还没有选择要打开的文件。";
fileName.text="";
}
}
private function mp3ziped():void
{
zipfile=File.documentsDirectory;
zipfile.browseForSave("保存为文件");
zipfile.addEventListener(Event.Select, savezip);
}
private function savezip(evt:Event):void
{
var zipStream:FileStream=new FileStream();
var zipByteArray:ByteArray=new ByteArray();
var file:File=new File(File.desktopDirectory.nativePath);
file=file.resolvePath("temp.abc");
tip.text="正写入文件";
zipMp3.serialize(zipByteArray);
zipStream.open(file, FileMode.WRITE);
zipStream.writeBytes(zipByteArray);
zipStream.close();
file.moveTo(zipfile, true);
tip.text="已经生成文件:" + zipfile.nativePath;
fileName.text="";
}
private function ioerr(evt:IOErrorEvent):void
{
tip.text="错误:" + evt.type;
}
]]>
</mx:Script>
</mx:WindowedApplication>
FZip 类下载:
http://codeazur.com.br/lab/fzip/
评论: 0 | 引用: 0 | 查看次数: -
发表评论
上一篇
下一篇

文章来自:
Tags: