代码之家  ›  专栏  ›  技术社区  ›  Darko

flex 3多重上传进度监控

  •  2
  • Darko  · 技术社区  · 16 年前

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

    我的问题是,用于上传的通用进度处理程序无法(我知道)指示正在进行的是哪个上传。我知道可以检查一个文件名,但是对于这个应用程序,多个上载的文件名可能是相同的。

    我的问题:对于一个通用的进度处理程序,如何区分两个具有相同文件名的多个上载?

    编辑: 回答者可能会认为我是一个完全没有弹性的新手…因为我是。

    3 回复  |  直到 15 年前
        1
  •  1
  •   Glenn    16 年前

    我用这个:

      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
  •   Cameron    16 年前

    如果您正在侦听ProgressEvents,这些事件具有 currentTarget 具有对已注册事件侦听器的对象的引用的属性。

    我假设您首先知道哪个文件上传对象与每个对象相匹配。

    编辑:使用文件引用的示例:

    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');
    
        3
  •  0
  •   Darko    15 年前

    我最终创建了自己的类,它为每个上载文件管理事件。

    推荐文章