Title: Re: [flexcoders] Download files
A couple of things to look out for.

#1 Make sure that your FileReference object is always in scope, otherwise when it goes out of scope, the download just cancels itself and you don’t get an error out.
#2 If you try to download something not on your server, you get a security error.

Here is a simple example of a Flex app that downloads. Enter a url on your server in the TextInput to download.  I took most of this code from the FileReference.download ASDocs.  By the way, if you defined your FileReference inside the function, it doesn’t work (I believe this is due to #1). Good luck.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >

<mx:Script>
<![CDATA[
    import flash.net.*;
    private var downloadURL:URLRequest;
        private var fileName:String = "SomeFile.gif";
        private var file:FileReference;
    
    public function myDownload(): void
    {
       downloadURL = new URLRequest();
       downloadURL.url = "">        file = new FileReference();
       configureListeners(file);
       file.download(downloadURL, fileName);
    }
    
    private function configureListeners(dispatcher:IEventDispatcher):void {
            dispatcher.addEventListener(Event.CANCEL, cancelHandler);
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
            dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            dispatcher.addEventListener(Event.OPEN, openHandler);
            dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
        }

        private function cancelHandler(event:Event):void {
            trace.text += "\ncancelHandler: " + event;
        }

        private function completeHandler(event:Event):void {
            trace.text += "\ncompleteHandler: " + event;
        }

        private function ioErrorHandler(event:IOErrorEvent):void {
            trace.text += "\nioErrorHandler: " + event;
        }

        private function openHandler(event:Event):void {
            trace.text += "\nopenHandler: " + event;
        }

        private function progressHandler(event:ProgressEvent):void {
            var file:FileReference = FileReference(event.target);
            trace.text += "\nprogressHandler name=" + file.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal;
        }

        private function securityErrorHandler(event:SecurityErrorEvent):void {
            trace.text += "\nsecurityErrorHandler: " + event;
        }


    
]]>
</mx:Script>

<mx:TextInput id="urlToLoad" width="400" />
<mx:Button label="download file" click="myDownload()" />
<mx:TextArea id="trace" width="500" height="400" />
</mx:Application>


On 7/6/06 8:57 AM, "Ingeniero Javier Cruz" <[EMAIL PROTECTED]> wrote:


 
 

Hello, I've a little problem ....

I've to build an application that takes a file from the server an then let the user to download the file. An already read about the FileReference and FileReferenceList classes but I can't make my app works. I made a mxml application that define a Script section in witch I create a FileReference object but when a test the application it doesn't work.
I'd like to prube with a servlet but I don't know how to start.

If somebody can, please help me I will thank for a long long time. Or, if someone knows about a site with examples that can help me, I'll thank too.


 

Horóscopos <http://ar.movil.yahoo.com/cont_horo.php> , Salud y belleza <http://ar.movil.yahoo.com/cont_salud.php> , Chistes <http://ar.movil.yahoo.com/contenidos.php> , Consejos de amor <http://ar.movil.yahoo.com/cont_adult.php> .
 El contenido más divertido para tu celular está en
Yahoo! Móvil <http://ar.movil.yahoo.com>
 
    

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to