Why has AIR file.browseForSave no FileFilter option

I try to create my own extension with a saved AIR file. The point in doing this is that the user knows what files are created by what program and a file without an extension is just plain ugly.

When you save a file in other programs you can choose to overwrite a file (that is created before or has a known extension) or create a new file. I tried to find a way in AIR to do this same thing. I found one article on an Adobe blog that uses a FileFilter in combination with a file.browseForSave but he is using it in a way that it has no effect and is pretty useless. He is creating a FileFilter but he is never using it:

var fileFilter = new air.FileFilter("To Do Lists", "*.todo");
ToDo.currentDirectory.addEventListener(air.Event.SELECT, ToDo.fileSaved.bind(ToDo) );
ToDo.currentDirectory.browseForSave("Save To-do List");

I hear you think “who cares about the FileFilter” because it sounds like a minor problem and maybe it is. But for me it seems easy to build because browse(), browseForOpen() and browseForOpenMultiple() are using it.

I wonder if there is a way to work around this problem. It is maybe a little detail but it are the little details that make things great.



7 responses to “Why has AIR file.browseForSave no FileFilter option”

  1. FreeFrag Avatar

    The reason they don’t do this is because Adobe doesn’t know what they’re doing. The method of locating files using AIR is, frankly, stupid. Instead of being able to tie everything into one function, you have to do it with three. It’s absurd and it feels like a waste of time.

  2. James Avatar

    Hi, I found your blog on this new directory of WordPress Blogs at blackhatbootcamp.com/listofwordpressblogs. I dont know how your blog came up, must have been a typo, i duno. Anyways, I just clicked it and here I am. Your blog looks good. Have a nice day. James.

  3. Peter Hughes Avatar
    Peter Hughes

    The users of my application will not be very computer literate – many of them do not have file extensions turned on, or do not even know what they are. The lack of a FileFilter for saves has already created trouble for me – just one of those little unexpected bugs that requires an explanation. It could enlarge an impression that my Flash product is second rate.

  4. Lumma Avatar

    Had the same problem
    Gladly, Stefan Richter’s approach did it for me – http://www.flashcomguru.com/index.cfm/2009/5/20/AIR-file-save-as

  5. Lubomir Avatar

    yep, there is no FileFilter for browseForSave…

    you can also try:

    var file:File = File.desktopDirectory.resolvePath("*.txt");

    this way, when the save dialog opens all text files (*.txt) will be filtered. however, since there is no actual filter specified, the input box will allow entering any filename and overwriting files with different extensions. to prevent that and to ensure that an extension is added try the following in the “listener” function:

    var selectedfile:File = File(event.target);
    var savetarget:String = selectedfile.url;
    if(savetarget.indexOf(".txt") == -1) savetarget += ".txt";
    var savefile:File = new File();
    savefile = savefile.resolvePath(savetarget);
    // save stream...

  6. Shivanno Avatar

    Lubomir: I try your way and worked like a charm, however i made a few tweaks in order to make shorter the code… this is how finally works for me :D:

    var selectedfile:File = File ( e.target)
    if ( selectedfile.extension == null ) selectedfile.nativePath +=”.txt”;
    stream.open( selectedfile, FileMode.WRITE );

  7. Adrian Smith Avatar
    Adrian Smith

    Lubomir: I also used your solution as is and it worked great!!!

    Many thanks.

    Adrian Smith

Leave a Reply

Your email address will not be published. Required fields are marked *