Adobe Air Writing a File throwing SecurityError: fileWriteResource - actionscript-3

I am trying to write into the file and everything was working fine upto the time i used File.desktopDirectory but after updating it with File.applicationDirectory lots of places i am getting security issue.
So overcome this issue i tried this code
File file = File.applicationDirectory.resolvePath("urlsList.properties");
var writeStream:FileStream = new FileStream();
var pathToFile:String = file.nativePath;
var destination:File = new File (pathToFile);
writeStream.open(destination, FileMode.WRITE);
file.moveTo (destination, true);
writeStream.close();
Now its throwing error at file.moveTo (destination, true);
SecurityError: fileWriteResource at flash.filesystem::File/moveTo()
at Demo/addNewUrl()[C:\Users\subodhc\Adobe Flash Builder
4.5\Demo\src\Demo.mxml:319] at Demo/writeFile()[C:\Users\subodhc\Adobe Flash Builder
4.5\Demo\src\Demo.mxml:283] at Demo/__deleteServerConfig023_click()[C:\Users\subodhc\Adobe Flash
Builder 4.5\Demo\src\Demo.mxml:575]

Related

Loading files in Android Mobile using AIR and Actionscript 3.0

Im building a Test Maker App. I need some help on loading files in Android mobile. The type i want is the type where the user can look for his file from a file browser. This is the code i have so far but it wont work. My mobile always says "No files were found".
var file = File.applicationStorageDirectory.resolvePath("saved projects");//This is a folder
file.browseForOpen("Open Your File", [new FileFilter("Text Files", "*.txt")]);
file.addEventListener(Event.SELECT, onFileSelected);
public function onFileSelected(e:Event):void {
var stream:FileStream = new FileStream();
stream.open(e.target as File, FileMode.READ);
loadTxt.text = stream.readUTF();
}
Plus additional question: Where is the best location to save files in the ANdroid mobile?
You can write your file manager, it should not be difficult. Scan a directory with method "getDirectoryListing":
var file:File = File.applicationDirectory.resolvePath('myDirectory/');
var filesList:Array = file.getDirectoryListing();
and show a list of files.

FileStream dosen´t work in actionscript 3 (Adobe Air)

I have a little problem here.. The code itself dosen´t get any errors, but it will not write to the .txt file... Hope someone can help me with this problem.
Here is my code:
test_btn.addEventListener(MouseEvent.CLICK, leggtil);
function leggtil(e:MouseEvent) {
var file:File = File.documentsDirectory.resolvePath("test.txt");
var fileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
var outputString:String = "test";
fileStream.writeUTFBytes(outputString);
fileStream.close();
}
I tested the code and it worked on my machine.
I believe that the code is working for you, but you're not aware of where the file has been written. Check your documents folder. In Windows, this would be C:\Users\[your user name]\Documents\. If you browse to that folder, you should see a file there named test.txt.

AIR Native process Error

I try to launch a programm with NativeProcess on Mac.
pathEV="/Applications/MyFolder/MyAppOSX.app"
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var fileEV:File = new File();
fileEV=fileEV.resolvePath(pathEV);
nativeProcessStartupInfo.executable = fileEV;
var process:NativeProcess = new NativeProcess();
process.start(nativeProcessStartupInfo);
But this error appear:
Error #3214: NativeProcessStartupInfo.executable does not specify a valid executable file
Can you help me to solve that?
Thanks
Haven't tested it yet, but I assume you'd need to run open with the path to your application as a parameter, like this:
pathEV:String="/Applications/MyFolder/MyAppOSX.app"
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var fileEV:File = new File();
fileEV=fileEV.resolvePath( '/usr/bin/open' );
nativeProcessStartupInfo.arguments = Vector.<String>([pathEV]);
nativeProcessStartupInfo.executable = fileEV;
var process:NativeProcess = new NativeProcess();
process.start(nativeProcessStartupInfo);
And yes, this definitely needs extendedDesktop rights
FYI: The Vector shizzle is correct, I use it to convert the array to Vector, not as a constructor function
Here's an explanation how to launch .app files from the terminal
Could it be that you need to add <supportedProfiles>extendedDesktop</supportedProfiles> to your manifest file?
Also, I believe.app is not an executable. Its actually just an application bundle within which exists the actual executable. Try pointing to /bin/ls first to make sure all else is OK and then dig inside the .app folder to find your executable.
Why do you need a nativeProcess? Why not just use fileEV.openWithDefaultApplication() ?

Loading URL directly VS Loading URLLoader

Im trying to load a php file from my server, loading the PHP's URL directly gives me instant results however loading it using as3 URLLoader takes around 15 seconds. I have no idea why nor what im doing wrong... any ideas?
this is how I'm coding it
// Build the varSend variable
varSend = new URLRequest(prefix + "php/myphpPage.php"); varSend.method = URLRequestMethod.POST;
varSend.data = variables;
varLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.TEXT;
varLoader.addEventListener(Event.COMPLETE, loadInitialInfo);
varLoader.addEventListener(IOErrorEvent.IO_ERROR,onIOError);
var0 = var0;
variables.sendRequest = "AAA";
// Send the data to the php file
varLoader.load(varSend);
thanks a lot

How can I load an HTML file using Flex StageView?

I want to display a HTML file for a mobile application using Flex Builder 4.5.
The following code does not work -
protected var webView:StageWebView = new StageWebView();
protected function view1_viewActivateHandler():void
{
if (StageWebView.isSupported)
{
webView.viewPort = new Rectangle(5, 80, stage.width-10, stage.height-9);
webView.stage = this.stage;
webView.loadURL("file:/assets/sample.html");
......
I get this error - Error #2044: Unhandled ErrorEvent:. text=Load error.
I am new to actionscript and flex.
The html file cannot be loaded using webView.loadURL("file:/assets/sample.html");
I found the reason and workaround here