1

i am downloading tiff images from WAMP server using our Flex AIR client. Using the following code for that.

public static function requestDownload(id:int, defaultName:String):void {
            //POST params
            var urlVars:URLVariables = new URLVariables();
            urlVars.action = "download";
            urlVars.fid = id;

            var urlReq:URLRequest = new URLRequest();
            urlReq.url = Config.getServerURL();
            urlReq.data = urlVars;

            Config.fileReference.addEventListener(Event.COMPLETE,FileDownload.requestDownloadResult);
            try {                   
            Config.fileReference.download(urlReq, defaultName);                                 

            }
            catch (e:Error) {                   
                Alert.show("Error in downloading the file");
            }

        }
        public static function requestDownloadResult(e:Event):void {    

            Alert.show("File downloaded");
        }

No issues with the download. It automatically prompts for a Save dialog. Works well. But i want to open the image being downloaded in a viewer(flash viewer or any) instead of the save dialog.

Please help me. Thanks Vish.

Blue Sky
  • 807
  • 1
  • 15
  • 36

1 Answers1

1

You can use a Loader or an SWFLoader class to load the image into your AIR application and then addChild it to present it to the... er, I see you're downloading tiff images.

Flash by default doesn't support tiff format - it allows only jpg, png and gif images. You're going to have to load it into a ByteArray using a URLLoader and parse it using some ActionScript TIFF encoder. Remember to set the dataFormat of URLLoader to URLLoaderDataFormat.BINARY

Amarghosh
  • 58,710
  • 11
  • 92
  • 121
  • Thanks Amar, will try it out, please let me know if you have any code snippets available. This link is not working, http://blog.kevinhoyt.org/2009/03/10/actionscript-3-tiff-encoder/ – Blue Sky May 26 '10 at 10:25
  • So when I download the image file from the server, can it be launched in a viewer? Want to enable/disable print options in the viewer based on the user permissions. But first need to get this thing working. If I can launch a tiff viewer on file download, that will be great. – Blue Sky May 27 '10 at 10:22
  • @Vish AIR (at least when I last worked on it a while ago) does not have support for system calls - so you cannot just launch an external viewer directly from AIR app. There is this AIR-Java bridge called merapi; you can use it to launch the viewer from java http://merapiproject.net/ – Amarghosh May 27 '10 at 10:41