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

31 responses to “Save file dialog with apollo hack”

  1. Abdul Qabiz Avatar

    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 Avatar

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

  3. yino Avatar

    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 Avatar

    Really cool shit!!! Keep up the good work

  5. pim Avatar

    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 Avatar
    Administrator

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

  7. Harry W. Avatar

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

  8. Rene furterer Avatar

    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 Avatar

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

  10. gymnasium Avatar

    it seems applo apps is very useful…

  11. Sportlernahrung Avatar

    i saved this tutorial! nice 1

  12. motoryzacja Avatar

    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 Avatar

    Jeah Budy,

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

  14. Steve Avatar

    Really nice Tutorial.

    Big Thanks

  15. Katalog Stron Avatar

    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 Avatar

    Really cool shit!!! Keep up the good work

  17. alexis johnson Avatar

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

    Big Thanks

  18. Anna Ruck Avatar

    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 Avatar

    Nice work! Thanks for the post.

    regards

  20. bahamut Avatar

    Thanks for this tutorial. Keep up the nice work!

    Regards,

    Bahamut

  21. Europe Avatar

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

  22. Zuti Avatar

    Works fine for me, thank you for this Tutorial!

  23. Stein Avatar

    Nice article .Thank’s

  24. Enzyklopädie Avatar

    I like this blog 🙂

  25. klimatyzatory Avatar

    Thanks for this article.

  26. Kabarety Avatar

    Very good code. thx

  27. Mielno Avatar

    Good work – good idea – thanks very much.

  28. videometry Avatar

    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/

  29. kupie Avatar

    Good work – good idea – thanks very much.

  30. Kuba Avatar

    Definately good work.Best Regards

Leave a Reply

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