The following code when run in air works great on the desktop. It allows you to select the file and unzip it and write it.
However, when I run it on my phone only "Audio", "Video" , "Images" files become avail able and I can't access a zip file I want to unzip from my phone. Here is the full code:
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;
import flash.filesystem.FileStream;
import flash.filesystem.FileMode;
var file:File;
var fileReference:FileReference;
var fileFilter:FileFilter;
var baseDir:File = File.documentsDirectory;
function unzip_init():void{
fileFilter = new FileFilter("selected your zip file.", "*");
file = new File();
**// This next line did not work and the one below that either. mistakes here!
//file.browseForDirectory("Choose a directory");**
file.browseForOpen("file://mnt/sdcard/", [fileFilter]);
file.addEventListener(Event.SELECT, onSelectedFile);
}
function onSelectedFile(e:Event):void
{
trace(file.nativePath);
var reader:ZipFileReader = new ZipFileReader();
reader.open(file);
var list:Array = reader.getEntries();
var i:int = 0;
for each(var entry:ZipEntry in list)
{
var filename:String = entry.getFilename();
if(entry.isDirectory())
{
trace("DIR --->" + entry.getFilename());
// If entry is directory
var dir:File = baseDir.resolvePath(filename);
dir.createDirectory();
}
else
{
trace("FILE --->" + entry.getFilename() + "(" + entry.getCompressRate() + ")");
var unzippedBytes:ByteArray = reader.unzip(entry);
//trace("btyes --->" + unzippedBytes);
var file:File = File.userDirectory.resolvePath(entry.getFilename());
var fs:FileStream = new FileStream();
fs.open(file,FileMode.WRITE);
fs.writeBytes(unzippedBytes,0,unzippedBytes.length);
fs.close();
}
}
reader.close();
}
unzip_init();