Adobe Air CreateDirectory common error

If you need to create a directory from Air and you dont know how, mostlikely you will use the Adobe Air Documentation and use something as the following:

var directory = air.File.documentsDirectory;
directory = directory.resolvePath(“AIR Test”);

air.trace(directory.exists); // true

it all looks nice and makes sense but in the real world it wont work, you would get an error like this:

Type Error : Value undefined ( result of expression air.File.createDirectory ) is not object.
# of your code error.

The problem with this approach is that the createDirectory method doesnt take any parameters, if you try to pass values directly to the method you will get this error:

Argument Error : Error #1063: Argument count mismatch on flash.filesystem::File/createDirectory(). Expected 0, got 1.

Once i was able to get this error I realized that the docs were wrong, or at least on this specific section. So looking at a different sample I figured out this works:

var directory = air.File.documentsDirectory;
directory = directory.resolvePath(“Air Test”);
directory.createDirectory();//no parameters necessary, Air knows where we need the new directory.

By first “asking” Air if the directory exists then Air knows where to create the new Directory rather than passing the property directly to the method.

This applies to Adobe Air SDK 3.0 and using Javascript

Tags: , , ,

← Back to home

2 thoughts on “Adobe Air CreateDirectory common error

Comments are closed.