Monitor the progress of multiple Flex 3 files

I have a Flex3 application that needs to be able to download multiple files and follow each individual file using the NOT progress progress label.

My problem is that the generic handler for downloads has no way (I know) to tell WHICH to download it, this is progressing. I know the filename is available to check, but in the case of this application, the filename may be the same for multiple downloads.

My question is, with a generic progress handler, how to distinguish between two multiple downloads of the same name?

EDIT: The responders may assume that I am a complete newb to Flex ... because I am.

+2


source to share


3 answers


As a result, I created my own class that manages events for each file uploaded



0


source


If you are listening to ProgressEvents, these events have an attribute currentTarget

that will refer to the object that registered the event listener.

I am assuming you know which file-loading object comes with each object first.



EDIT: An example using FileReference:

import flash.net.FileReference;
import flash.events.ProgressEvent;
import flash.utils.Dictionary;

public var files:Dictionary = new Dictionary();     // This will hold all the FileReference objects

public function loadFile(id:String):void
{
    var file:FileReference = new FileReference();

    // Listen for the progress event on this FileReference... will call the same function for every progress event
    file.addEventListener(ProgressEvent.PROGRESS, onProgress);

    // TODO: listen for errors and actually upload a file, etc.

    // Add file to the dictionary (as key), with value set to an object containing the id
    files[file] = { 'id': id };
}

public function onProgress(event:ProgressEvent):void
{
    // Determine which FileReference dispatched thi progress event:
    var file:FileReference = FileReference(event.target);

    // Get the ID of the FileReference which dispatched this function:
    var id:String = files[file].id;

    // Determine the current progress for this file (in percent):
    var progress:Number = event.bytesLoaded / event.bytesTotal;

    trace('File "' + id + '" is ' + progress + '% done uploading');
}


// Load some files:
loadFile('the first file');
loadFile('the second file');

      

+1


source


I am using this:

  private function _addFileListeners(dispatcher:IEventDispatcher):void {
      dispatcher.addEventListener(Event.OPEN, this._handleFileOpen);
        dispatcher.addEventListener(Event.SELECT, this._handleFileOpen);
        dispatcher.addEventListener(Event.CANCEL, this._handleFileCancel);
        dispatcher.addEventListener(ProgressEvent.PROGRESS, this._handleFileProgress);
        dispatcher.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,this._handleFileComplete);
        dispatcher.addEventListener(IOErrorEvent.IO_ERROR, this._handleError);
        dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this._handleError);
    }

      

where "dispatcher" is a file:

        for (var i:uint = 0; i < fileList.length; i++) {
            file = FileReference(fileList[i]);
            this._addFileListeners(file);
            this._pendingFiles.push(file);
        }

      

and a sample handler:

    private function _handleFileOpen(e:Event):void {
        var file:FileReference = FileReference(e.target);
        ...
    }

      

I'm not sure how you want to differentiate between two files with the same name. In my case, I am sending files to a queue. This way, only one file is downloaded at a time. (PendingFiles).

+1


source







All Articles