Search code examples
apache-flexactionscript-3filereference

FileReference.download() not working


I'm building a Flex app which requires me to download files.

I have the following code:

public function execute(event:CairngormEvent) : void
{
    var evt:StemDownloadEvent = event as StemDownloadEvent;
    var req:URLRequest = new URLRequest(evt.data.file_path);
    var localRef:FileReference = new FileReference();

    localRef.addEventListener(Event.OPEN, _open);
    localRef.addEventListener(ProgressEvent.PROGRESS, _progress);
    localRef.addEventListener(Event.COMPLETE, _complete);
    localRef.addEventListener(Event.CANCEL, _cancel);
    localRef.addEventListener(Event.SELECT, _select);
    localRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, _securityError);
    localRef.addEventListener(IOErrorEvent.IO_ERROR, _ioError);

    try {
        localRef.download(req);
    } catch (e:Error) {
        SoundRoom.logger.log(e);
    }
}

As you can see, I hooked up every possible event listener as well.

When this executes, I get the browse window, and am able to select a location, and click save. After that, nothing happens.

I have each event handler hooked up to my logger, and not a single one is being called! Is there something missing here?


Solution

  • The problem seems to be with my command being destroyed before this could finish.

    For a proof of concept, I set my localRef variable to be static instead of an instance variable, and everything went through successfully! I guess Cairngorm commands kill themselves asap!