I’m using the below code to write images and other files to the user’s hard drive with AIR. The problem is that it takes the whole path of the image, relative to where the image is initially (so if the image is in root/images/engligh) it writes on the user’s hard drive to C:/images/english, and creates those folders. I’ve tried several ways of truncating the path, but that always causing the file to not be found.
public function onDownloaded(evt:Event)
{
var filename:String = this.fileList[this.currentFile];
saveFile( file.nativePath + "/" + filename, evt );
this.currentFile++;
if ( this.currentFile < this.fileList.length )
{
loadFile();
}
else
{
showCompleteScreen();
}
}
//--------------------------------------------------------------------------------
// Write file to hard drive
public function saveFile( filename:String, evt:Event )
{
var myFile:File = File.resolvePath( filename );
var myFileStream:FileStream = new FileStream();
myFileStream.open( myFile, FileMode.WRITE );
myFileStream.writeBytes( evt.target.data, 0, evt.target.data );
}