I’ve got an interactive presentation, and it’s all working as it should.
Now I want to add a function to download the currently visible image/video.
Because this presentation has a lot of files (all stored under assets/…) and it’s a pain to navigate through the assets, I want an easy way to just click a button and get a “Save as..” window.
I’ve managed to get the url of the media, so now I just need a way to show a “save as..” dialog to allow the users to save/download the file and save it locally.
This whole presentation should be put online, so all the files are located somewhere in the /assets/.. folder inside the project.
Any ideas of how to do this? =)
Thanks!
EDIT #1:
For now I’m using “navigateToURL” to open a new browser window with the media. This works, but is there a way to show a “Save as..” dialog instead of opening the image?
Or any other ways to do this? =)
You are looking for the FileReference class, in particular the
FileReference.save( data:*,defaultFileName:String = null )method. That will open up a “Save…” dialog to save the corresponding data object and allow you to set a default file name. I’m unsure if this class can also handle the download as I have never had a time when I needed to prompt to save something that was to be downloaded. If it cannot handle it, you’ll need to look into the URLStream class. That can handle the download and either on ProgressEvent.PROGRESS or Event.COMPLETE, you simply do aURLStream.readBytes( byteArray );to save the downloaded bytes to a ByteArray and then that is the data object you save. I would look into the FileReference class, though. Odds are it can handle downloads as well.