views:

164

answers:

1

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?

A: 

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!

Lowgain
You don't have an instance variable. You have a local variable, which will go out of scope when the function returns. Hence, it's eligible for garbage collection. Have you tried declaring localRef as an instance variable? (i.e. in your class def, but outside the method). It seems to me that using static is asking for trouble... Now, if your command is actually collected (I'm not familiar with Cairngorm) then, you might have to resort to static (or changin your approach)
Juan Pablo Califano
I used the wrong word (instance over local), my solution worked regardless B-)
Lowgain