pol2095
I will brief the situation of the app requirement.
Below is the code for the final requirement functioning call.
function saveFile(fFile) {
var usrDeviceIDStream = new FileStream();
var usrDeviceIDFile: File = fFile.resolvePath("id.txt");
usrDeviceIDStream.open(usrDeviceIDFile, FileMode.WRITE);
usrDeviceIDStream.writeUTFBytes("File from as3");
usrDeviceIDStream.close();
}
App required the internal path of the mobile as direct File.documentsDirectory.resolvePath("loc") will not work so I used :
var vFile:File = new File();
var data;
function fileAccessCheck() {
vFile.addEventListener(Event.SELECT, dirSelect);
vFile.browseForDirectory("Select the Directory");
data = vFile.url;
}
So I saved the vFile.url into the File.applicationStorageDirectory.resolvePath("fileLoc.txt");
var sFile:File = File.applicationStorageDirectory.resolvePath("fileLoc.txt");
var sFileStream:FileStream = new FileStream();
sFileStream.open(sFile, FileMode.WRITE);
sFileStream.writeUTFBytes(data); // data has content of vFile.url
sFileStream.close();
saveFile(vFile);
When I recheck the to saved file :
function fileCheck() {
var sFile:File = File.applicationStorageDirectory.resolvePath("fileLoc.txt");
var sFileStream:FileStream = new FileStream();
if (sFile.exists) {
sFileStream.open(sFile, FileMode.READ);
var str = sFileStream.readUTFBytes(sFileStream.bytesAvailable);
pFile.nativePath = str;
saveFile(pFile);
} else {
fileAccessCheck();
}
}
Even if I change the url to the native path we get error :
ArgumentError: Error #2004: One of the parameters is invalid.
at Error$/throwError()
at flash.filesystem::File/set nativePath()
at Function/file1_fla:MainTimeline/but2Fn/file1_fla:fileCheck()[file1_fla.MainTimeline::frame1:20]
at file1_fla::MainTimeline/but2Fn()[file1_fla.MainTimeline::frame1:11]
I also sharing the final file please check. While debugging in animate CC, there is one button in center and then first click we get the intent from browse for directory. Then is saved the location of the browsed directory's url to the app storage directory. When again click to the same button then it get break the script.
File below for reference :
https://drive.google.com/file/d/13wAlAtkwIOtX47cCZ0DrrFWqa-Yv5vLV/view?usp=sharing