8/9/2010 1:41:41 AM
Title:
Error
I am getting this error while wrting to a file why this is happening please help.
SecurityError: fileWriteResource
at runtime::SecurityManager$/checkPrivilegeForCaller()
at flash.filesystem::FileStream/open()
The code is below.
var file:File = File.applicationDirectory.resolvePath("file.txt");
// var file:File = File.documentsDirectory.resolvePath("test.txt"); // to store in documents directory.
var fs:FileStream = new FileStream();
fs.open(file, FileMode.WRITE);
fs.writeUTFBytes("hello");
fs.close();
8/9/2010 1:58:23 AM
I think you need to declare the client property for filestream and attach the metadata handler to fix this error. here is the actionscript code
var client:Object = new Object();
client.onMetaData = function(metadata:Object):void {
}
fs.client = client;
8/9/2010 2:11:31 AM
fs.client = client; is showing an error
is there anything to import.
Shawn
Points: 680
Posts:0
8/9/2010 2:51:09 AM
this should work
var appDirectoryPath:File = File.applicationDirectory;
var nativePathToAppDirectory:String = appDirectoryPath.nativePath.toString();
nativePathToAppDirectory+= "file.txt";
var file:File = new File(nativePathToAppDirectory);
var fstream:FileStream = new FileStream();
fstream.open(file, FileMode.WRITE);
fstream.writeUTFBytes("My Text to be written");
fstream.close();
8/9/2010 3:01:28 AM
Thankyou shawn for the help
Now the error has gone,but the file is not created.
any guess.
Shawn
Points: 680
Posts:0
8/9/2010 4:20:38 AM
make sure your directory is not read only