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

Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+Pin on Pinterest

31 thoughts on “Save file dialog with apollo hack

  1. 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. 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.

  3. 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

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

  5. 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!

  6. 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 :)

Leave a Reply

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