Save file dialog with apollo hack

One thing that is currently missing from the Apollo Filesystem-API is the ability to get a native save file dialog.
It`s easy to create a file open dialog with the open()-Method of the File Object. So until the File Object gets a save() method i use the download()-Method.
The File class extends FileReference and so inherits its download()-Method. The problem is that the download Method takes a URLRequest Object as a parameter.
So after the OPEN event make sure to cancel the download request with file.cancel(). Now you can access the url via the normal File attributes.
Here is some example code:

private function saveFile():void
{
file=new File();
file.download(new URLRequest(”http://www.nourl.de”),”exported.swf”);
file.addEventListener(Event.OPEN,swfSavePathSelected);
file.addEventListener(IOErrorEvent.IO_ERROR,savePathSelected);
}

private function savePathSelected(evt:Event) : void
{
file.cancel();
fileStream = new FileStream();
fileStream.openAsync(file, FileMode.WRITE);
fileStream.writeBytes(b);
fileStream.close()
}

This worked great for me in earlier projects. At some point i got some errors which seem to be related to the nonexisting url and the app would just hang. In order to avoid this
i did an quich and ugly hack. I also added an event listener for the IO_ERROR event and did all the saving stuff their. Not nice but temporarily fixed it. I got confirmation that
the missing save()-method will be somehow implemented in later builds, so i can live with this hack in the meantime.
Anyone got a better solution?

UPDATE:
Found this post by Robots w/Lasers that has more about this

Comments

30 Responses to “Save file dialog with apollo hack”

  1. Abdul Qabiz on March 29th, 2007 2:29 pm

    It’s nice way of doing. I noticed this way doing things in Josh Tynjala’s Bittorrent app..

    I find it better than MXML components :)

    -abdul

  2. Alex MacCaw on March 31st, 2007 11:52 pm

    You might want to specify what ‘b’ is (’writeBytes(b)’).

  3. yino on April 5th, 2007 3:46 pm

    I used same way(Robots w/Lasers’s way) to for save flvfile in this application.(http://www.yino.sakura.ne.jp/YoutubePlayer.air)
    (this application watch youtube video, save it’s, and play
    flv file)

    But this way has a bug in Mac.

    When called file.download method,
    Apollo application was failed in Mac .

    As far as I examined it,
    Apollo runtime has a bug about file access method.

    So, we seem to have to wait apolloruntime version UP for file access in mac.

    My English is clumsy, so I’m sorry.

    thanks for read my Msg.

  4. Maikel Sibbald on April 20th, 2007 9:43 am

    Really cool shit!!! Keep up the good work

  5. pim on May 15th, 2007 3:50 pm

    Why not use FileReference.download() ?
    Somehow most of people use it only to upload but it’s good for download too, it opens a dialog box etc …

    Pim

  6. Administrator on May 15th, 2007 4:36 pm

    Hey Pim,
    that`s exactly what i`m doing as File is a subclass of FileReference ;-)

  7. Harry W. on June 28th, 2007 8:42 am

    A quite intresting idea is realized in this website! And a good and easy to handle design has been found too!

  8. Rene furterer on July 31st, 2007 10:46 pm

    I used same way(Robots w/Lasers’s way) to for save flvfile in this application.(http://www.yino.sakura.ne.jp/YoutubePlayer.air)
    (this application watch youtube video, save it’s, and play
    flv file)

  9. Tomasz Gorski on August 9th, 2007 4:20 pm

    Thanks for great tutorial now i know how to save it!

  10. gymnasium on August 12th, 2007 2:53 pm

    it seems applo apps is very useful…

  11. Sportlernahrung on September 4th, 2007 12:30 pm

    i saved this tutorial! nice 1

  12. motoryzacja on September 14th, 2007 2:55 am

    awwwhh..I have searching fot his in last 3 days and finnaly I found it here THANKS !!

    function is easy and I love easy cases. I’ll back here soon to check if you create new release :)
    Thanks man!

  13. madb on September 17th, 2007 1:40 pm

    Jeah Budy,

    thats a nice Gimmick. A friend of mine used it, and it works perfect. Thanks a lot.

  14. Steve on September 22nd, 2007 11:27 pm

    Really nice Tutorial.

    Big Thanks

  15. Katalog Stron on September 23rd, 2007 2:03 pm

    Great Article, please more write, i love read..
    that`s exactly what i`m doing as File is a subclass of FileReferenc, Thanks ! for you @->-

  16. Linki on September 26th, 2007 10:12 am

    Really cool shit!!! Keep up the good work

  17. alexis johnson on September 28th, 2007 3:46 pm

    Great Article, please more write, i love read..
    Really nice Tutorial.

    Big Thanks

  18. Anna Ruck on October 6th, 2007 11:27 am

    I’ve some problem with this section in 4 line;

    FileStream not declared error blabla..

    Why I cant find a class for this function ?

    Damn.. I’m lazyy :)

  19. Meteko on October 22nd, 2007 8:35 am

    Nice work! Thanks for the post.

    regards

  20. bahamut on October 26th, 2007 5:00 am

    Thanks for this tutorial. Keep up the nice work!

    Regards,

    Bahamut

  21. Europe on October 28th, 2007 11:54 pm

    Not only nice article but all the articles . Keep up the work.

  22. Zuti on November 1st, 2007 2:44 am

    Works fine for me, thank you for this Tutorial!

  23. Stein on November 21st, 2007 4:24 pm

    Nice article .Thank’s

  24. Enzyklopädie on November 21st, 2007 4:29 pm

    I like this blog :)

  25. klimatyzatory on November 21st, 2007 6:27 pm

    Thanks for this article.

  26. Tworzenie stron on December 17th, 2007 8:15 pm

    Good work !

  27. Kabarety on December 29th, 2007 12:11 pm

    Very good code. thx

  28. Mielno on July 31st, 2008 11:01 am

    Good work – good idea – thanks very much.

  29. videometry on April 30th, 2009 2:44 pm

    For anyone still using this hack, there is now an official function in AIR which seems to work :O)
    Check out Mike Chambers example here:
    http://www.mikechambers.com/blog/2007/11/06/air-example-html-editor-with-live-preview/

  30. kupie on May 14th, 2009 1:37 am

    Good work – good idea – thanks very much.

Leave a Reply