"Save As" in flash
- Started
- Last post
- 18 Responses
- dbloc
Is there a way to do a right click save as command for a flash link to download hi res images?
I could zip them up and force them to download them, but a save as command would be cool.
anyone done this?
- lvl_130
i would think this would be possible.
here is an example for mx2004
http://www.developertutorials.co…
- fyoucher10
ContextMenu class...
- kult0
You can't code Flash to download an image to a user's selected local directory, but you can do something like write a small custom template page which accepts an image URL and generates the download request there, and have Flash popup this page. Not very elegant though.
- not true you can use file reference for this:
http://livedocs.adob…flashbender
- not true you can use file reference for this:
- fyoucher10
Check to see if mouse is over image, set ContextMenu links to something new (i.e. Save Image As...)..button links to hi-rez version...
- fugged0
you can add menu items to the contextual menus through the ContextMenu class (as3, as2)
Then either navigate the URL of the image, or use PHP or the likes to modify the headers in the request to force a download (http://us3.php.net/header)
- dbloc0
found it.
- fugged0
Fuck - totally forgot about the FileReference object. Thanks for the reminder.
- I've used File.Reference with very good resultsflashbender
- dbloc0
import flash.net.FileReference;
var fileRef:FileReference = new FileReference();var cm:ContextMenu = new ContextMenu();
cm.customItems.push(new ContextMenuItem("Download Image", saveAs));function saveAs() {
fileRef.download(_root._url);
}
this.menu = cm;
cm.hideBuiltInItems();
function doSomething(){}
cm.customItems.push(Functioned);
- dbloc0
actually this doesn't work...it's trying to download the swf file
- fugged0
you need to point it to the url of the image. _root._url is the urt of the swf
- fugged0
where is the hires image coming from? are you loading it into the swf via the loader class?
- dbloc0
just in a folder on the server. the link links to it to open in a new window
- acescence0
function saveAs():void {
var yourURL:URLRequest = new URLRequest ( "the url");
fileRef.download(yourURL);
}- doesn't seem to be workingdbloc
- needs to be an absolute urlmaximillion_
- fugged0
are you supplying a valid URL to the fileRef.download method?
- dbloc0
would this be the code for the button or just on the first frame?
the url would change per button
- maximillion_0
function saveAs():void {
var yourURL:URLRequest = new URLRequest ( "the url");
fileRef.download(yourURL, filename);
}
the url here needs to be abolsute and include the filename, download() method takes 2 params the second should be the filename used at the end of the absolute url
- fugged0
not knowing how you implemented things, it's hard to make suggestions that make sense.
My understanding is that you have a bunch of images that have hires versions that you want the user to be able to download upon selecting a menu item from the contextual menu? So you'll need some method of storing all of the urls for the hi-res versions or at least some way for deriving the url.
There's a million and one different ways of doing this.
Personally, I would probably use a Dictionary object that stores the filename for the images, using the object that is firing the menu selection event as the key.
then when an event is fired, you can use the events target to pull the filename out of the dictionary object and construct your url from there.
I'd place hi res and low res versions in separate folders and use the same file names for the images. That way you can find the path to the image with something like small/[filename] and large/[filename].
not sure if that makes any sense, or if it works with how you have things set up :)