2009-09-20 36 views
2

我有一个Flex3应用程序,必须能够上传多个文件,并使用标签而不是进度条监控每个文件的单个进度。Flex 3多重上传进度监控

我的问题是,上传的通用进度处理程序没有办法(我知道)指示上传它是否正在进行。我知道一个文件名可以检查,但在这个应用程序的情况下,文件名可能是相同的多个上传。

我的问题:使用通用进度处理程序如何区分具有相同文件名的2次多次上传?

编辑:回答者可能会认为我是Flex的总新手......因为我是。

回答

0

我结束了创建我自己的类管理事件每个上传文件

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'); 
+0

我认为这已注册的进度事件的对象是文件的参考?好吧,说我有2个对象 - FileReference和我可以用来跟踪文件的对象。如何将progressEvent附加到跟踪对象,以便在文件引用的上载时触发它?或者我想这是错误的方式? – 2009-09-20 21:15:55

+0

我会编辑我的答案,举一个例子 – Cameron 2009-09-21 23:24:34

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

其中 “调度员” 是文件:

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

我不确定你想如何区分具有相同名称的两个文件。在我的情况下,我发送队列中的文件。因此,一次只能上传1个文件。 (pendingFiles)。

+0

感谢Glen,我使用自定义写入队列,但是我确实需要能够一次上传2+文件,所以问题仍然存在 - 我当前的实现非常相似 – 2009-09-20 23:32:48

+0

无论如何,你需要一些方法来识别它们,所以你甚至可以使用一个数组。然后,当你得到一个fileReference时,你可以说“fileArray.indexOf(fileRef)”来找到它的索引。这将是独一无二的。或者如果你有文件的键,你可以使用一个对象。 – Glenn 2009-09-20 23:48:12