ארכיון

רשומות עם התג ‘swc’

Save Image As for Flash

10 אפריל, 2009 gadi_sr 4 תגובות

So this post is in English for a global usage, since it relevant to much wider audience.
One of the things not implemented in swf files is the ability to right-click an image and download it to a specific library just as done in HTML pages. this ability is very nice-to-have and there are no technology barrirers (except issue that I will mention later) for most of the standard functionality.

My goal was to create a menu similar to HTML Image right-click menu with the following functionality:

1. View Image - open the image in external window/tab
2. Copy Image - copy image content to clipboard for paste in paint etc.
3. Copy Image Location - copy url to clipboard for paste in browser address bar
4. Save Image As - open browse window to save image locally.

I couldn't manage to do 2. since flash access to clipboard is for string data only, although maybe using Alchemy might solve this issue, so data will be delivered to clipboard by C/C++ code, you are most welcome to try.

View Image mission was accomplished by using Loader.contentLoaderInfo.url as path to the image. Copy Image part was made by setting clipboard data as the same url of the previous part and Save Image as has done using 2 steps:

1. Creating encoded data as PNG/JPG using standard Adobe libraries for encoding
2. Using FP 10 FileReference.save ability to save data from byteArray created by the application on the client Desktop without requiring server side scripting development.

The Implementation class is a Decorator for Loader Class and use in the following manner:

import il.flashdev.common.Downloadable;

var loader:Loader = new Loader();
loader.load(new URLRequest(myImagePath));
addChild(loader);
loader = new Downloadble(loader);

here is the result:

download example

Parameters available for the Downloadable constructor:
loader:Loader - Loader instance
viewImageItem:Boolean - should display View Image in Context menu
copyImageLocationItem:Boolean - should display Copy Image Location in Context menu
saveImageAsItem:Boolean - should display Save Image As in Context menu
imageFormat:String - in case not mentioned in Loader object, what is the image format to be saved
imageName:String - in case not mentioned in Loader object, what is the image name to be saved

defaults are: new Downloadable(loader, true, true, true, "", "");

you can use swc files here, or from inside fla

enjoy

  • Share/Save/Bookmark