Uploader.as revision fc85028e135879c5ba1824dde83c71c11e372711
230N/A import com.yahoo.util.YUIBridge;
230N/A import flash.display.Loader;
230N/A import flash.display.Sprite;
230N/A import flash.display.StageAlign;
230N/A import flash.display.StageScaleMode;
230N/A import flash.events.DataEvent;
230N/A import flash.events.Event;
230N/A import flash.events.FocusEvent;
230N/A import flash.events.HTTPStatusEvent;
230N/A import flash.events.IOErrorEvent;
230N/A import flash.events.KeyboardEvent;
230N/A import flash.events.MouseEvent;
230N/A import flash.events.ProgressEvent;
230N/A import flash.net.FileFilter;
230N/A import flash.net.FileReference;
230N/A import flash.net.FileReferenceList;
230N/A import flash.net.URLRequest;
230N/A import flash.net.URLVariables;
230N/A import flash.ui.Keyboard;
230N/A import flash.utils.Dictionary;
230N/A yuiBridge = new YUIBridge(this.stage);
this.simultaneousUploadLimit = simUploadLimit;
* e.g. "*.jpg;*.gif;*.png".
if (this.allowLog != allowLogging) {
this.allowLog = allowLogging;
this.allowMultiple = allowMultipleFiles;
singleFile.browse(filterArray);
multipleFiles.browse(filterArray);
buttonSkin.y = 0;
buttonSkin.y = -3*buttonHeight;
* Uploads a file corresponding to a specified ID to a specified path where a script handles writing to the server.
* @param headers An object containing variables that should be set as headers in the POST request. The following header names
* Accept-Charset, Accept-Encoding, Accept-Ranges, Age, Allow, Allowed, Authorization, Charge-To, Connect, Connection,
* Content-Length, Content-Location, Content-Range, Cookie, Date, Delete, ETag, Expect, Get, Head, Host, Keep-Alive,
* Last-Modified, Location, Max-Forwards, Options, Post, Proxy-Authenticate, Proxy-Authorization, Proxy-Connection,
* Public, Put, Range, Referer, Request-Range, Retry-After, Server, TE, Trace, Trailer, Transfer-Encoding, Upgrade,
public function upload(fileID:String, url:String, method:String = "GET", vars:Object = null, fieldName:String = "Filedata"):void {
fr.upload(request,fieldName);
* @param fieldName The field name that precedes the file data in the upload POST operation. The uploadDataFieldName value must be non-null and a non-empty String.
public function uploadThese(fileIDs:Array, url:String, method:String = "GET", vars:Object = null, fieldName:String = "Filedata"):void {
* @param fieldName The field name that precedes the file data in the upload POST operation. The uploadDataFieldName value must be non-null and a non-empty String.
* @param headers An object containing variables that should be set as headers in the POST request. The following header names
* Accept-Charset, Accept-Encoding, Accept-Ranges, Age, Allow, Allowed, Authorization, Charge-To, Connect, Connection,
* Content-Length, Content-Location, Content-Range, Cookie, Date, Delete, ETag, Expect, Get, Head, Host, Keep-Alive,
* Last-Modified, Location, Max-Forwards, Options, Post, Proxy-Authenticate, Proxy-Authorization, Proxy-Connection,
* Public, Put, Range, Referer, Request-Range, Retry-After, Server, TE, Trace, Trailer, Transfer-Encoding, Upgrade,
public function uploadAll(url:String, method:String = "GET", vars:Object = null, fieldName:String = "Filedata", headers:Object = null):void {
* Cancels either an upload of the file corresponding to a given fileID, or in the absence of the specified fileID, all active files being uploaded.
item.cancel();
if (this.currentUploadThreads > 0)
fr.cancel();
fileSelect - fires when the user selects one or more files (after browse is called). Passes the array of currently selected files (if prior browse calls were made and clearFileList hasn't been called, all files the user has ever selected will be returned), along with all information available about them (name, size, type, creationDate, modificationDate, creator).
uploadProgress - fires when a file upload reports progress. Passes the file id, as well as bytesUploaded and bytesTotal for the given file.
uploadComplete - fires when a file upload is completed successfully and passes the corresponding file id.
uploadCompleteData - fires when data is received from the server after upload and passes the corresponding file id and the said data.
uploadError - fires when an error occurs during download. Passes the id of the file that was being uploaded and an error type.
newEvent.type = "mousedown";
yuiBridge.sendEvent(newEvent);
newEvent.type = "mouseup";
yuiBridge.sendEvent(newEvent);
newEvent.type = "mouseenter";
yuiBridge.sendEvent(newEvent);
newEvent.type = "mouseleave";
yuiBridge.sendEvent(newEvent);
newEvent.type = "click";
yuiBridge.sendEvent(newEvent);
logMessage("Dispatching uploadstart event for " + fileIDList[event.target]);
newEvent.type = "uploadstart";
yuiBridge.sendEvent(newEvent);
logMessage("Dispatching uploadprogress event for " + fileIDList[event.target] + ": " + event.bytesLoaded.toString() + " / " + event.bytesTotal.toString());
newEvent.type = "uploadprogress"
yuiBridge.sendEvent(newEvent);
logMessage("Dispatching uploadcomplete event for " + fileIDList[event.target]);
newEvent.type = "uploadcomplete"
yuiBridge.sendEvent(newEvent);
logMessage("Dispatching uploadcompletedata event for " + fileIDList[event.target] + ": ");
logMessage("Received the following data: " + event.data);
newEvent.type = "uploadcompletedata"
yuiBridge.sendEvent(newEvent);
logMessage("Dispatching uploadcancel event for " + fileIDList[event.target]);
newEvent.type = "uploadcancel";
yuiBridge.sendEvent(newEvent);
logMessage("IO error for " + fileIDList[event.target] + ". Likely causes are problems with Internet connection or server misconfiguration.");
logMessage("Security error for " + fileIDList[event.target]);
logMessage ("Dispatching error event for " + fileIDList[event.target]);
newEvent.type = "uploaderror";
yuiBridge.sendEvent(newEvent);
addFile(event.target as FileReference);
for each (var currentFR:FileReference in currentFRL.fileList) {
buttonSkin.load(new URLRequest(buttonSkinSprite));
buttonSprite.addChild(buttonSkin);
buttonHeight = buttonSkin.height/4;
buttonWidth = buttonSkin.width;
buttonMask.graphics.beginFill(0x000000,1);
buttonMask.graphics.drawRect(0,0,buttonWidth,buttonHeight);
_this.addChild(buttonMask);
buttonSprite.mask = buttonMask;
_this.stage.tabChildren = false;
_this.addChild(buttonSprite);
buttonSkin.y = -1*buttonHeight;
buttonSkin.y = 0;
buttonSkin.y = -2*buttonHeight;
buttonSkin.y = 0;
buttonSprite.graphics.beginFill(0xffffff, 0);
buttonSprite.graphics.drawRect(0,0,5,5);
this.stage.tabChildren = false;
this.buttonMode = true;
this.useHandCursor = true;
this.addChild(buttonSprite);
buttonSkin.y = -2*buttonHeight;
buttonSkin.y = 0;
btnSkinURL = yuiBridge.flashvars["buttonSkin"];
this.renderType = "button";
this.renderAsButton(btnSkinURL);
this.renderType = "transparent";
yuiBridge.addCallbacks ({removeFile:removeFile, clearFileList:clearFileList, upload:upload,uploadThese:uploadThese,uploadAll:uploadAll,cancel:cancel,setAllowLogging:setAllowLogging,setAllowMultipleFiles:setAllowMultipleFiles,setSimUploadLimit:setSimUploadLimit,setFileFilters:setFileFilters,enable:enable, disable:disable});
// ExternalInterface.addCallback("removeFile", removeFile);
// ExternalInterface.addCallback("clearFileList", clearFileList);
// upload(fileID:String, url:String, method:String = "GET", vars:Object = null, fieldName:String = "Filedata")
// Uploads the specified file in a specified POST variable, attaching other variables using the specified method
// ExternalInterface.addCallback("upload", upload);
//ExternalInterface.addCallback("uploadThese", uploadThese);
//ExternalInterface.addCallback("uploadAll", uploadAll);
//ExternalInterface.addCallback("cancel", cancel);
//ExternalInterface.addCallback("setAllowLogging", setAllowLogging);
//ExternalInterface.addCallback("enable", enable);
//ExternalInterface.addCallback("disable", disable);
// TODO: Should we have an 'allowedExtensions' property that the JS user accesses directly? Potential here for typos ('extension' instead of 'extensions') as well as a misunderstanding of the nature of the expected array
for (var i:int = 0; i < filtersArray.length; i++) {
filtersArray[i] = new FileFilter(filtersArray[i].description, filtersArray[i].extensions, filtersArray[i].macType);
dstring += item.name + "\n ";
newEvent.fileList = fileDataList;
newEvent.type = "fileselect"
yuiBridge.sendEvent(newEvent);
var fileName:String = fr.name;
var fileCDate:Date = fr.creationDate;
var fileMDate:Date = fr.modificationDate;
var fileSize:Number = fr.size;
fileDataList[fileID] = {id: fileID, name: fileName, cDate: fileCDate, mDate: fileMDate, size: fileSize};//, type: fileType, creator: fileCreator};
filesToUpload.push( {fr:fr, request:request, fieldName:fieldName });
var objToUpload:Object = filesToUpload.shift();
var fr:FileReference = objToUpload.fr;
var request:URLRequest = objToUpload.request;
var fieldName:String = objToUpload.fieldName;
logMessage("Starting upload for " + objToUpload.id);
fr.upload(request,fieldName);
* Creates a URLRequest object from a url, and optionally includes an HTTP request method and additional variables to be sent
request.url = url;
request.method = method;
request.data = new URLVariables();
request.data[itemName] = vars[itemName];
if (this.allowLog) {