有难度问题,高手请入
先看as代码(来自国外):
package com.newmediateam.fileIO{ import flash.events.*; import flash.net.FileFilter; import flash.net.FileReference; import flash.net.FileReferenceList; import flash.net.URLRequest; import flash.net.URLVariables; import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.controls.Button; import mx.controls.DataGrid; import mx.controls.ProgressBar; import mx.controls.dataGridClasses.*; import mx.events.CollectionEvent; public class MultiFileUpload { //Events public var completeEvent:Event; //UI Vars private var _datagrid:DataGrid; private var _browsebutton:Button; private var _remselbutton:Button; private var _remallbutton:Button; private var _uploadbutton:Button; private var _progressbar:ProgressBar; private var _testButton:Button; //DataGrid Columns private var _nameColumn:DataGridColumn; private var _typeColumn:DataGridColumn; private var _sizeColumn:DataGridColumn; private var _creationDate:DataGridColumn; private var _modificationDate:DataGridColumn; private var _progressColumn:DataGridColumn; private var _columns:Array; //File Reference Vars [Bindable] public var _files:ArrayCollection; private var _fileref:FileReferenceList private var _file:FileReference; private var _uploadURL:URLRequest; public var _totalbytes:Number; //File Filter vars private var _filefilter:Array; private var imageTypes:FileFilter=new FileFilter("文件类型 (*.jpg; *.jpeg; *.gif; *.png;*.rar;*.zip;*.pdf;*.doc;*.docx;*.xls;*.xlsx;*.mpg;*.rm;*.rmvb;*.mp3)", "*.jpg; *.jpeg; *.gif; *.png;*.rar;*.zip;*.pdf;*.doc;*.docx;*.xls;*.xlsx;*.mpg;*.rm;*.rmvb;*.mp3"); //private var videoTypes:FileFilter = new FileFilter("Flash Video Files (*.flv)","*.flv"); //private var documentTypes:FileFilter = new FileFilter("Documents (*.pdf)",("*.pdf")); private var allTypes:Array=new Array(imageTypes); //,videoTypes,documentTypes); //config vars private var _url:String; // location of the file upload handler can be a relative path or FQDM private var _maxFileSize:Number; //bytes private var _variables:URLVariables; //variables to passed along to the file upload handler on the server. //Constructor public function MultiFileUpload(dataGrid:DataGrid, browseButton:Button, removeAllButton:Button, removeSelectedButton:Button, uploadButton:Button, progressBar:ProgressBar, url:String, variables:URLVariables, maxFileSize:Number) { _datagrid=dataGrid; _browsebutton=browseButton; _remallbutton=removeAllButton; _remselbutton=removeSelectedButton; _uploadbutton=uploadButton; _url=url; _progressbar=progressBar; _variables=variables; _maxFileSize=maxFileSize; init(); } //Initialize private function init():void { _files=new ArrayCollection(); _fileref=new FileReferenceList; _file=new FileReference; _totalbytes=0; _browsebutton.addEventListener(MouseEvent.CLICK, browseFiles); _uploadbutton.addEventListener(MouseEvent.CLICK, uploadFiles); _remallbutton.addEventListener(MouseEvent.CLICK, clearFileQue); _remselbutton.addEventListener(MouseEvent.CLICK, removeSelectedFileFromQue); _fileref.addEventListener(Event.SELECT, selectHandler); _files.addEventListener(CollectionEvent.COLLECTION_CHANGE, popDataGrid); _nameColumn=new DataGridColumn; _typeColumn=new DataGridColumn; _sizeColumn=new DataGridColumn; _nameColumn.dataField="name"; _nameColumn.headerText="文件名"; _typeColumn.dataField="type"; _typeColumn.headerText="文件类型"; _typeColumn.width=80; _sizeColumn.dataField="size"; _sizeColumn.headerText="文件大小"; _sizeColumn.labelFunction=bytesToKilobytes as Function; _sizeColumn.width=150; _progressbar.mode="manual"; _progressbar.label=""; _uploadbutton.enabled=false; _remselbutton.enabled=false; _remallbutton.enabled=false; _columns=new Array(_nameColumn, _typeColumn, _sizeColumn); _datagrid.columns=_columns _datagrid.sortableColumns=false; _datagrid.dataProvider=_files; _datagrid.dragEnabled=true; _datagrid.dragMoveEnabled=true; _datagrid.dropEnabled=true; _uploadURL=new URLRequest; _uploadURL.url=_url; _uploadURL.method="POST"; _uploadURL.data=_variables; _uploadURL.contentType="multipart/form-data"; }