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
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
You might want to specify what ‘b’ is (‘writeBytes(b)’).
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.
Really cool shit!!! Keep up the good work
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
Hey Pim,
that`s exactly what i`m doing as File is a subclass of FileReference 😉
A quite intresting idea is realized in this website! And a good and easy to handle design has been found too!
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)
Thanks for great tutorial now i know how to save it!
it seems applo apps is very useful…
i saved this tutorial! nice 1
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!
Jeah Budy,
thats a nice Gimmick. A friend of mine used it, and it works perfect. Thanks a lot.
Really nice Tutorial.
Big Thanks
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 @->-
Really cool shit!!! Keep up the good work
Great Article, please more write, i love read..
Really nice Tutorial.
Big Thanks
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
Nice work! Thanks for the post.
regards
Thanks for this tutorial. Keep up the nice work!
Regards,
Bahamut
Not only nice article but all the articles . Keep up the work.
Works fine for me, thank you for this Tutorial!
Nice article .Thank’s
I like this blog
Thanks for this article.
Good work !
Very good code. thx
Good work – good idea – thanks very much.
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/
Good work – good idea – thanks very much.
Definately good work.Best Regards