FlashUploader.as revision ec749fdeacb8e11cb7a9dd6dcebd1538b953059e
13117N/A import com.yahoo.util.YUIBridge;
13117N/A import flash.display.Loader;
13117N/A import flash.display.DisplayObject;
13117N/A import flash.display.Sprite;
13117N/A import flash.display.StageAlign;
13117N/A import flash.display.StageScaleMode;
13117N/A import flash.events.DataEvent;
13117N/A import flash.events.Event;
import flash.events.HTTPStatusEvent;
import flash.events.IOErrorEvent;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.external.ExternalInterface;
import flash.net.FileFilter;
import flash.net.FileReference;
import flash.net.FileReferenceList;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.ui.Keyboard;
import flash.utils.Dictionary;
import flash.utils.setTimeout;
import flash.filters.GlowFilter;
import flash.accessibility.*;
yuiBridge = new YUIBridge(this.stage);
yuiBridge.addCallbacks ({clearFileList:clearFileList, upload:upload,cancel:cancel,setAllowMultipleFiles:setAllowMultipleFiles,setSimUploadLimit:setSimUploadLimit,setFileFilters:setFileFilters,enable:enable, disable:disable});
_accProps.silent = false;
_accProps.name = "Select Files button";
_accProps.description = "Select Files button";
this.accessibilityProperties = _accProps;
if(Accessibility.active) {
this.yuiBridge.sendEvent({type:"trace", message: msg});
// trace("key received: " + evt.keyCode);
switch (evt.keyCode) {
if (evt.shiftKey) {
this.yuiBridge.sendEvent({type:"tabback"});
this.yuiBridge.sendEvent({type:"tabforward"});
if (this.enabled) {
this.handleMouseClick(new MouseEvent("mousevent"));
buttonSprite.graphics.beginFill(0xffffff, 0);
buttonSprite.graphics.drawRect(0,0,5,5);
buttonSprite.tabEnabled = false;
this.stage.tabChildren = false;
this.buttonMode = true;
this.useHandCursor = true;
this.tabEnabled = false;
this.enable();
this.addChild(buttonSprite);
this.simultaneousUploadLimit = simUploadLimit;
for (var i:int = 0; i < filtersArray.length; i++) {
this.filterArray = filtersArray;
this.allowMultiple = allowMultipleFiles;
//yuiBridge.log("setAllowMultipleFiles has been called, and the allowMultiple value is now " + this.allowMultiple);
singleFile.browse(filterArray);
multipleFiles.browse(filterArray);
this.enabled = true;
this.enabled = false;
this.fileList = {};
public function upload(fileID:String, url:String, vars:Object = null, fieldName:String = "Filedata"):void {
this.log("upload has been called");
this.log("The url is " + url);
var file:File = this.fileList[fileID];
var fr:FileReference = file.fileReference;
fr.upload(request, fieldName);
this.filesInProgress[fileID] = file;
for each (var item:File in this.filesInProgress) {
this.filesInProgress = {};
this.log("mouseclick");
newEvent.type = "click";
yuiBridge.sendEvent(newEvent);
this.log("mousedown");
newEvent.type = "mousedown";
yuiBridge.sendEvent(newEvent);
this.log("mouseup");
newEvent.type = "mouseup";
yuiBridge.sendEvent(newEvent);
this.log("rollover");
newEvent.type = "mouseenter";
yuiBridge.sendEvent(newEvent);
this.log("rollout");
newEvent.type = "mouseleave";
yuiBridge.sendEvent(newEvent);
newEvent.type = "uploadstart";
yuiBridge.sendEvent(newEvent);
this.log("PROGRESS fired for: " + event.target.fileReference.name + ":::" + event.bytesLoaded + ":::" + event.bytesTotal);
newEvent.type = "uploadprogress";
yuiBridge.sendEvent(newEvent);
newEvent.type = "uploadcomplete";
yuiBridge.sendEvent(newEvent);
newEvent.type = "uploadcompletedata";
yuiBridge.sendEvent(newEvent);
newEvent.type = "uploadcancel";
yuiBridge.sendEvent(newEvent);
this.log("The event text is " + (event as IOErrorEvent).text);
newEvent.source="io";
newEvent.message = (event as IOErrorEvent).text;
this.log("The event status is " + (event as HTTPStatusEvent).status);
newEvent.source="http";
newEvent.message = (event as HTTPStatusEvent).status;
this.log("Error details / " + itemName + ": " + event[itemName]);
yuiBridge.sendEvent(newEvent);
var newFile:File = addFile(event.target as FileReference);
var currentFRL:FileReferenceList = event.target as FileReferenceList;
for each (var currentFR:FileReference in currentFRL.fileList) {
addedFiles.push(addFile(currentFR));
newEvent.fileList = selectedFiles;
newEvent.type = "fileselect";
yuiBridge.sendEvent(newEvent);
fileList[newFile.fileId] = newFile;
* 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];