Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put\save files into your application directory? (adobe air)

How to put\save files into your application directory? (adobe air) (code example, please)

like image 504
Rella Avatar asked May 20 '10 08:05

Rella


People also ask

Is Adobe AIR still supported?

Adobe has announced it will end support for Adobe AIR on the 31st December 2020. This includes releasing security updates for the once popular cross platform development tool for websites and applications.

What is air in Adobe animate?

Adobe AIR (also known as Adobe Integrated Runtime and is codenamed Apollo) is a cross-platform runtime system currently developed by Harman International, in collaboration with Adobe Inc., for building desktop applications and mobile applications, programmed using Adobe Animate, ActionScript, and optionally Apache Flex ...

What is AIR for desktop?

Adobe® AIR™ is a cross-operating system runtime that allows you to leverage your existing web development skills (Adobe® Animate®, Adobe® Flex™, Adobe® Flash Builder™ HTML, JavaScript®, Ajax) to build and deploy Rich Internet Applications (RIAs) to the desktop.


4 Answers

@glendon if you try to save directly to applicationDirectory it will indeed throw an error, but it seems you can move the file in the filesystem. i used the code below after yours:

var sourceFile:File = File.applicationStorageDirectory.resolvePath ("file.txt");
var pathToFile:String = File.applicationDirectory.resolvePath ('file.txt').nativePath;
var destination:File = new File (pathToFile);
sourceFile.moveTo (destination, true);

the reason why you 'shouldnt' use the application folder is because not all users have rights to save files in such folder, while everyone will in applicationStorageDirectory.

like image 164
joe Avatar answered Sep 29 '22 20:09

joe


It's not recomended but it is possible. Construct your File reference like this:

var pathToFile:String = File.applicationDirectory.resolvePath('file.txt').nativePath;
var someFile:File = new File(pathToFile);
like image 35
Miroslav Avatar answered Sep 29 '22 18:09

Miroslav


You can't write to your AIR app's Application Directory, it's not allowed. You can however write to a folder that your AIR app creates in the user's directory, called the Application Storage Directory. If you need config files and the like, that's probably the best place to put them. See 'applicationDirectory' in the docs link below:

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/

like image 37
debu Avatar answered Sep 29 '22 18:09

debu


The accepted answer works!

But if I do this instead:

var vFile = File.applicationDirectory.resolvePath('file.txt');
var vStream = new FileStream();
vStream.open(vFile, FileMode.WRITE);
vStream.writeUTFBytes("Hello World");
vStream.close();

It will give SecurityError: fileWriteResource. However, if I use applicationStorageDirectory instead, the above code will work. It'll only NOT work if it's applicationDirectory. Moreover, Adobe's documentation also says that an AIR app cannot write to its applicationDirectory.

Now, I wonder if it's a bug on Adobe's part that they allow writing to the applicationDirectory using the way suggested by the accepted answer.

like image 42
glendon Avatar answered Sep 29 '22 18:09

glendon