_nameColumn.headerText= "File";
_typeColumn.dataField = "type";
_typeColumn.headerText = "File Type";
_typeColumn.width = 80;
_sizeColumn.dataField = "size";
_sizeColumn.headerText = "File Size";
_sizeColumn.labelFunction = bytesToKilobytes as Function;
_sizeColumn.width = 150;
_columns = new Array(_nameColumn,_typeColumn,_sizeColumn);
_datagrid.columns = _columns
_datagrid.sortableColumns = false;
_datagrid.dataProvider = _files;
_datagrid.dragEnabled = true;
_datagrid.dragMoveEnabled = true;
_datagrid.dropEnabled = true;
// Set Up URLRequest
_uploadURL = new URLRequest;
_uploadURL.url = _url;
_uploadURL.method = "GET"; // this can also be set to "POST" depending on your needs
_uploadURL.data = _variables;
_uploadURL.contentType = "multipart/form-data";
}
/********************************************************
* PRIVATE METHODS *
********************************************************/
//Browse for files
private function browseFiles(event:Event):void{
_fileref.browse(_filefilter);
}
//Upload File Cue
private function uploadFiles(event:Event):void{
if (_files.length > 0){
_file = FileReference(_files.getItemAt(0));
_file.addEventListener(Event.OPEN, openHandler);
_file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
_file.addEventListener(Event.COMPLETE, completeHandler);
_file.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler);
_file.addEventListener(HTTPStatusEvent.HTTP_STATUS,httpStatusHandler);
_file.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
_file.upload(_uploadURL);
setupCancelButton(true);
}
}
//Remove Selected File From Cue
private function removeSelectedFileFromCue(event:Event):void{
if (_datagrid.selectedIndex >= 0){
_files.removeItemAt( _datagrid.selectedIndex);
}
}
//Remove all files from the upload cue;
private function clearFileCue(event:Event):void{
_files.removeAll();
}
// Cancel Current File Upload
private function cancelFileIO(event:Event):void{
_file.cancel();
setupCancelButton(false);
checkCue();
}
//label function for the datagird File Size Column
private function bytesToKilobytes(data:Object,blank:Object):String {
var kilobytes:String;
kilobytes = String(Math.round(data.size/ 1024)) + ' kb';
return kilobytes
}
// Feed the progress bar a meaningful label
private function getByteCount():void{
var i:int;
_totalbytes = 0;
for(i=0;i < _files.length;i++){
_totalbytes += _files[i].size;
}
_progressbar.label = "Total Files: "+ _files.length+ " Total Size: " + Math.round(_totalbytes/1024) + " kb"
}
// Checks the files do not exceed maxFileSize | if _maxFileSize == 0 No File Limit Set
private function checkFileSize(filesize:Number):Boolean{
var r:Boolean = false;
//if filesize greater then _maxFileSize
if (filesize > _maxFileSize){
r = false;