2

複数のファイルをアップロードし、進行状況バーではなくラベルを使用して各ファイルの個々の進行状況を監視できる必要があるFlex3アプリケーションがあります。

私の問題は、アップロードの一般的な進行状況ハンドラーには、進行中のアップロードがどれであるかを示す方法がないことです(私が知っていることです)。ファイル名を確認できることは知っていますが、このアプリの場合、ファイル名は複数のアップロードで同じである可能性があります。

私の質問:一般的なプログレスハンドラーを使用すると、同じファイル名の2つの複数のアップロードをどのように区別できますか?

編集:回答者は、私がFlexのまったくの初心者であると想定する場合があります...私はそうだからです。

4

3 に答える 3

1

私はこれを使用します:

  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);
    }

ここで、「dispatcher」はファイルです。

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

およびサンプル ハンドラー:

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

同じ名前の 2 つのファイルをどのように区別したいのかわかりません。私の場合、ファイルをキューで送信します。そのため、一度にアップロードされるファイルは 1 つだけです。(保留中のファイル)。

于 2009-09-20T23:22:26.690 に答える
1

ProgressEvents をリッスンしている場合、これらのイベントにはcurrentTarget、イベント リスナーを登録したオブジェクトへの参照を持つ属性があります。

そもそも、どのファイルアップロードオブジェクトが各オブジェクトに対応するかを知っていると思います。

編集: 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');
于 2009-09-20T21:11:47.187 に答える