Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import flash.net.*;
- class FileItem {
- private static var file_id_sequence:Number = 0;
- public static var FILE_STATUS_QUEUED:int = -1;
- public static var FILE_STATUS_IN_PROGRESS:int = -2;
- public static var FILE_STATUS_ERROR:int = -3;
- public static var FILE_STATUS_SUCCESS:int = -4;
- public static var FILE_STATUS_CANCELLED:int = -5;
- public static var FILE_STATUS_NEW:int = -6;
- private var postObject:Object;
- public var file_reference:FileReference;
- public var id:String;
- public var index:Number = -1;
- public var file_status:int = 0;
- private var js_object:Object;
- public function FileItem(_arg1:FileReference, _arg2:String, _arg3:Number){
- var file_reference:* = _arg1;
- var control_id:* = _arg2;
- var index:* = _arg3;
- super();
- this.postObject = {};
- this.file_reference = file_reference;
- this.id = ((control_id + "_") + FileItem.file_id_sequence++);
- this.file_status = FileItem.FILE_STATUS_NEW;
- this.index = index;
- this.js_object = {
- id:this.id,
- index:this.index,
- post:this.GetPostObject()
- };
- try {
- this.js_object.name = this.file_reference.name;
- this.js_object.size = this.file_reference.size;
- this.js_object.type = ((this.file_reference.type) || (""));
- this.js_object.creationdate = ((this.file_reference.creationDate) || (new Date(0)));
- this.js_object.modificationdate = ((this.file_reference.modificationDate) || (new Date(0)));
- } catch(ex:Error) {
- this.file_status = FileItem.FILE_STATUS_ERROR;
- };
- this.js_object.filestatus = this.file_status;
- }
- public static function EscapeParamName(_arg1:String):String{
- _arg1 = _arg1.replace(/[^a-z0-9_]/gi, FileItem.EscapeCharacter);
- _arg1 = _arg1.replace(/^[0-9]/, FileItem.EscapeCharacter);
- return (_arg1);
- }
- public static function EscapeCharacter():String{
- return (("$" + ("0000" + arguments[0].charCodeAt(0).toString(16)).substr(-4, 4)));
- }
- public function AddParam(_arg1:String, _arg2:String):void{
- this.postObject[_arg1] = _arg2;
- }
- public function RemoveParam(_arg1:String):void{
- delete this.postObject[_arg1];
- }
- public function GetPostObject(_arg1:Boolean=false):Object{
- var _local2:Object;
- var _local3:String;
- var _local4:String;
- if (_arg1){
- _local2 = {};
- for (_local3 in this.postObject) {
- if (this.postObject.hasOwnProperty(_local3)){
- _local4 = FileItem.EscapeParamName(_local3);
- _local2[_local4] = this.postObject[_local3];
- };
- };
- return (_local2);
- };
- return (this.postObject);
- }
- public function ToJavaScriptObject():Object{
- this.js_object.filestatus = this.file_status;
- this.js_object.post = this.GetPostObject(true);
- return (this.js_object);
- }
- public function toString():String{
- return (("FileItem - ID: " + this.id));
- }
- }
- }//package
- package {
- import flash.external.*;
- class ExternalCall {
- public static function Simple(_arg1:String):void{
- ExternalInterface.call(_arg1);
- }
- public static function FileQueued(_arg1:String, _arg2:Object):void{
- ExternalInterface.call(_arg1, EscapeMessage(_arg2));
- }
- public static function FileQueueError(_arg1:String, _arg2:Number, _arg3:Object, _arg4:String):void{
- ExternalInterface.call(_arg1, EscapeMessage(_arg3), EscapeMessage(_arg2), EscapeMessage(_arg4));
- }
- public static function FileDialogComplete(_arg1:String, _arg2:Number, _arg3:Number, _arg4:Number):void{
- ExternalInterface.call(_arg1, EscapeMessage(_arg2), EscapeMessage(_arg3), EscapeMessage(_arg4));
- }
- public static function UploadStart(_arg1:String, _arg2:Object):void{
- ExternalInterface.call(_arg1, EscapeMessage(_arg2));
- }
- public static function UploadProgress(_arg1:String, _arg2:Object, _arg3:uint, _arg4:uint):void{
- ExternalInterface.call(_arg1, EscapeMessage(_arg2), EscapeMessage(_arg3), EscapeMessage(_arg4));
- }
- public static function UploadSuccess(_arg1:String, _arg2:Object, _arg3:String, _arg4:Boolean):void{
- ExternalInterface.call(_arg1, EscapeMessage(_arg2), EscapeMessage(_arg3), EscapeMessage(_arg4));
- }
- public static function UploadError(_arg1:String, _arg2:Number, _arg3:Object, _arg4:String):void{
- ExternalInterface.call(_arg1, EscapeMessage(_arg3), EscapeMessage(_arg2), EscapeMessage(_arg4));
- }
- public static function UploadComplete(_arg1:String, _arg2:Object):void{
- ExternalInterface.call(_arg1, EscapeMessage(_arg2));
- }
- public static function Debug(_arg1:String, _arg2:String):void{
- ExternalInterface.call(_arg1, EscapeMessage(_arg2));
- }
- public static function Bool(_arg1:String):Boolean{
- return (ExternalInterface.call(_arg1));
- }
- private static function EscapeMessage(_arg1){
- if ((_arg1 is String)){
- _arg1 = EscapeString(_arg1);
- } else {
- if ((_arg1 is Array)){
- _arg1 = EscapeArray(_arg1);
- } else {
- if ((_arg1 is Object)){
- _arg1 = EscapeObject(_arg1);
- };
- };
- };
- return (_arg1);
- }
- private static function EscapeString(_arg1:String):String{
- var _local2:RegExp = /\\/g;
- return (_arg1.replace(_local2, "\\\\"));
- }
- private static function EscapeArray(_arg1:Array):Array{
- var _local2:uint = _arg1.length;
- var _local3:uint;
- while (_local3 < _local2) {
- _arg1[_local3] = EscapeMessage(_arg1[_local3]);
- _local3++;
- };
- return (_arg1);
- }
- private static function EscapeObject(_arg1:Object):Object{
- var _local2:String;
- for (_local2 in _arg1) {
- _arg1[_local2] = EscapeMessage(_arg1[_local2]);
- };
- return (_arg1);
- }
- }
- }//package
- package {
- import flash.events.*;
- import flash.net.*;
- import flash.display.*;
- import flash.utils.*;
- import flash.text.*;
- import flash.external.*;
- import flash.xml.*;
- public class SWFUpload extends Sprite {
- private const build_number:String = "SWFUPLOAD 2.2.0";
- private var fileBrowserMany:FileReferenceList;
- private var fileBrowserOne:FileReference = null;
- private var file_queue:Array;
- private var current_file_item:FileItem = null;
- private var file_index:Array;
- private var successful_uploads:Number = 0;
- private var queue_errors:Number = 0;
- private var upload_errors:Number = 0;
- private var upload_cancelled:Number = 0;
- private var queued_uploads:Number = 0;
- private var valid_file_extensions:Array;
- private var serverDataTimer:Timer = null;
- private var assumeSuccessTimer:Timer = null;
- private var restoreExtIntTimer:Timer;
- private var hasCalledFlashReady:Boolean = false;
- private var flashReady_Callback:String;
- private var fileDialogStart_Callback:String;
- private var fileQueued_Callback:String;
- private var fileQueueError_Callback:String;
- private var fileDialogComplete_Callback:String;
- private var uploadStart_Callback:String;
- private var uploadProgress_Callback:String;
- private var uploadError_Callback:String;
- private var uploadSuccess_Callback:String;
- private var uploadComplete_Callback:String;
- private var debug_Callback:String;
- private var testExternalInterface_Callback:String;
- private var cleanUp_Callback:String;
- private var movieName:String;
- private var uploadURL:String;
- private var filePostName:String;
- private var uploadPostObject:Object;
- private var fileTypes:String;
- private var fileTypesDescription:String;
- private var fileSizeLimit:Number;
- private var fileUploadLimit:Number = 0;
- private var fileQueueLimit:Number = 0;
- private var useQueryString:Boolean = false;
- private var requeueOnError:Boolean = false;
- private var httpSuccess:Array;
- private var assumeSuccessTimeout:Number = 0;
- private var debugEnabled:Boolean;
- private var buttonLoader:Loader;
- private var buttonTextField:TextField;
- private var buttonCursorSprite:Sprite;
- private var buttonImageURL:String;
- private var buttonWidth:Number;
- private var buttonHeight:Number;
- private var buttonText:String;
- private var buttonTextStyle:String;
- private var buttonTextTopPadding:Number;
- private var buttonTextLeftPadding:Number;
- private var buttonAction:Number;
- private var buttonCursor:Number;
- private var buttonStateOver:Boolean;
- private var buttonStateMouseDown:Boolean;
- private var buttonStateDisabled:Boolean;
- private var SIZE_TOO_BIG:Number = 1;
- private var SIZE_ZERO_BYTE:Number = -1;
- private var SIZE_OK:Number = 0;
- private var ERROR_CODE_QUEUE_LIMIT_EXCEEDED:Number = -100;
- private var ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT:Number = -110;
- private var ERROR_CODE_ZERO_BYTE_FILE:Number = -120;
- private var ERROR_CODE_INVALID_FILETYPE:Number = -130;
- private var ERROR_CODE_HTTP_ERROR:Number = -200;
- private var ERROR_CODE_MISSING_UPLOAD_URL:Number = -210;
- private var ERROR_CODE_IO_ERROR:Number = -220;
- private var ERROR_CODE_SECURITY_ERROR:Number = -230;
- private var ERROR_CODE_UPLOAD_LIMIT_EXCEEDED:Number = -240;
- private var ERROR_CODE_UPLOAD_FAILED:Number = -250;
- private var ERROR_CODE_SPECIFIED_FILE_ID_NOT_FOUND:Number = -260;
- private var ERROR_CODE_FILE_VALIDATION_FAILED:Number = -270;
- private var ERROR_CODE_FILE_CANCELLED:Number = -280;
- private var ERROR_CODE_UPLOAD_STOPPED:Number = -290;
- private var BUTTON_ACTION_SELECT_FILE:Number = -100;
- private var BUTTON_ACTION_SELECT_FILES:Number = -110;
- private var BUTTON_ACTION_START_UPLOAD:Number = -120;
- private var BUTTON_CURSOR_ARROW:Number = -1;
- private var BUTTON_CURSOR_HAND:Number = -2;
- public function SWFUpload(){
- var self:* = null;
- var oSelf:* = null;
- this.fileBrowserMany = new FileReferenceList();
- this.file_queue = new Array();
- this.file_index = new Array();
- this.valid_file_extensions = new Array();
- this.httpSuccess = [];
- super();
- if (((((((((((!(FileReferenceList)) || (!(FileReference)))) || (!(URLRequest)))) || (!(ExternalInterface)))) || (!(ExternalInterface.available)))) || (!(DataEvent.UPLOAD_COMPLETE_DATA)))){
- return;
- };
- var counter:* = 0;
- root.addEventListener(Event.ENTER_FRAME, function ():void{
- if (++counter > 100){
- counter = 0;
- };
- });
- this.fileBrowserMany.addEventListener(Event.SELECT, this.Select_Many_Handler);
- this.fileBrowserMany.addEventListener(Event.CANCEL, this.DialogCancelled_Handler);
- this.stage.align = StageAlign.TOP_LEFT;
- this.stage.scaleMode = StageScaleMode.NO_SCALE;
- this.buttonLoader = new Loader();
- var doNothing:* = function ():void{
- };
- this.buttonLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, doNothing);
- this.buttonLoader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, doNothing);
- this.stage.addChild(this.buttonLoader);
- self = this;
- this.stage.addEventListener(MouseEvent.CLICK, function (_arg1:MouseEvent):void{
- self.UpdateButtonState();
- self.ButtonClickHandler(_arg1);
- });
- this.stage.addEventListener(MouseEvent.MOUSE_DOWN, function (_arg1:MouseEvent):void{
- self.buttonStateMouseDown = true;
- self.UpdateButtonState();
- });
- this.stage.addEventListener(MouseEvent.MOUSE_UP, function (_arg1:MouseEvent):void{
- self.buttonStateMouseDown = false;
- self.UpdateButtonState();
- });
- this.stage.addEventListener(MouseEvent.MOUSE_OVER, function (_arg1:MouseEvent):void{
- self.buttonStateMouseDown = _arg1.buttonDown;
- self.buttonStateOver = true;
- self.UpdateButtonState();
- });
- this.stage.addEventListener(MouseEvent.MOUSE_OUT, function (_arg1:MouseEvent):void{
- self.buttonStateMouseDown = false;
- self.buttonStateOver = false;
- self.UpdateButtonState();
- });
- this.stage.addEventListener(Event.MOUSE_LEAVE, function (_arg1:Event):void{
- self.buttonStateMouseDown = false;
- self.buttonStateOver = false;
- self.UpdateButtonState();
- });
- this.buttonTextField = new TextField();
- this.buttonTextField.type = TextFieldType.DYNAMIC;
- this.buttonTextField.antiAliasType = AntiAliasType.ADVANCED;
- this.buttonTextField.autoSize = TextFieldAutoSize.NONE;
- this.buttonTextField.cacheAsBitmap = true;
- this.buttonTextField.multiline = true;
- this.buttonTextField.wordWrap = false;
- this.buttonTextField.tabEnabled = false;
- this.buttonTextField.background = false;
- this.buttonTextField.border = false;
- this.buttonTextField.selectable = false;
- this.buttonTextField.condenseWhite = true;
- this.stage.addChild(this.buttonTextField);
- this.buttonCursorSprite = new Sprite();
- this.buttonCursorSprite.graphics.beginFill(0xFFFFFF, 0);
- this.buttonCursorSprite.graphics.drawRect(0, 0, 1, 1);
- this.buttonCursorSprite.graphics.endFill();
- this.buttonCursorSprite.buttonMode = true;
- this.buttonCursorSprite.x = 0;
- this.buttonCursorSprite.y = 0;
- this.buttonCursorSprite.addEventListener(MouseEvent.CLICK, doNothing);
- this.stage.addChild(this.buttonCursorSprite);
- this.movieName = ((root.loaderInfo.parameters.movieName) || (""));
- this.movieName = this.movieName.replace(/[^a-zA-Z0-9\_\.\-]/g, "");
- this.flashReady_Callback = (("SWFUpload.instances[\"" + this.movieName) + "\"].flashReady");
- this.fileDialogStart_Callback = (("SWFUpload.instances[\"" + this.movieName) + "\"].fileDialogStart");
- this.fileQueued_Callback = (("SWFUpload.instances[\"" + this.movieName) + "\"].fileQueued");
- this.fileQueueError_Callback = (("SWFUpload.instances[\"" + this.movieName) + "\"].fileQueueError");
- this.fileDialogComplete_Callback = (("SWFUpload.instances[\"" + this.movieName) + "\"].fileDialogComplete");
- this.uploadStart_Callback = (("SWFUpload.instances[\"" + this.movieName) + "\"].uploadStart");
- this.uploadProgress_Callback = (("SWFUpload.instances[\"" + this.movieName) + "\"].uploadProgress");
- this.uploadError_Callback = (("SWFUpload.instances[\"" + this.movieName) + "\"].uploadError");
- this.uploadSuccess_Callback = (("SWFUpload.instances[\"" + this.movieName) + "\"].uploadSuccess");
- this.uploadComplete_Callback = (("SWFUpload.instances[\"" + this.movieName) + "\"].uploadComplete");
- this.debug_Callback = (("SWFUpload.instances[\"" + this.movieName) + "\"].debug");
- this.testExternalInterface_Callback = (("SWFUpload.instances[\"" + this.movieName) + "\"].testExternalInterface");
- this.cleanUp_Callback = (("SWFUpload.instances[\"" + this.movieName) + "\"].cleanUp");
- this.uploadURL = root.loaderInfo.parameters.uploadURL;
- this.filePostName = root.loaderInfo.parameters.filePostName;
- this.fileTypes = root.loaderInfo.parameters.fileTypes;
- this.fileTypesDescription = (((root.loaderInfo.parameters.fileTypesDescription + " (") + this.fileTypes) + ")");
- this.loadPostParams(root.loaderInfo.parameters.params);
- if (!this.filePostName){
- this.filePostName = "Filedata";
- };
- if (!this.fileTypes){
- this.fileTypes = "*.*";
- };
- if (!this.fileTypesDescription){
- this.fileTypesDescription = "All Files";
- };
- this.LoadFileExensions(this.fileTypes);
- try {
- this.debugEnabled = ((root.loaderInfo.parameters.debugEnabled == "true")) ? true : false;
- } catch(ex:Object) {
- this.debugEnabled = false;
- };
- try {
- this.SetFileSizeLimit(String(root.loaderInfo.parameters.fileSizeLimit));
- } catch(ex:Object) {
- this.fileSizeLimit = 0;
- };
- try {
- this.fileUploadLimit = Number(root.loaderInfo.parameters.fileUploadLimit);
- if (this.fileUploadLimit < 0){
- this.fileUploadLimit = 0;
- };
- } catch(ex:Object) {
- this.fileUploadLimit = 0;
- };
- try {
- this.fileQueueLimit = Number(root.loaderInfo.parameters.fileQueueLimit);
- if (this.fileQueueLimit < 0){
- this.fileQueueLimit = 0;
- };
- } catch(ex:Object) {
- this.fileQueueLimit = 0;
- };
- if ((((this.fileQueueLimit > this.fileUploadLimit)) && (!((this.fileUploadLimit == 0))))){
- this.fileQueueLimit = this.fileUploadLimit;
- };
- if ((((this.fileQueueLimit == 0)) && (!((this.fileUploadLimit == 0))))){
- this.fileQueueLimit = this.fileUploadLimit;
- };
- try {
- this.useQueryString = ((root.loaderInfo.parameters.useQueryString == "true")) ? true : false;
- } catch(ex:Object) {
- this.useQueryString = false;
- };
- try {
- this.requeueOnError = ((root.loaderInfo.parameters.requeueOnError == "true")) ? true : false;
- } catch(ex:Object) {
- this.requeueOnError = false;
- };
- try {
- this.SetHTTPSuccess(String(root.loaderInfo.parameters.httpSuccess));
- } catch(ex:Object) {
- this.SetHTTPSuccess([]);
- };
- try {
- this.SetAssumeSuccessTimeout(Number(root.loaderInfo.parameters.assumeSuccessTimeout));
- } catch(ex:Object) {
- this.SetAssumeSuccessTimeout(0);
- };
- try {
- this.SetButtonDimensions(Number(root.loaderInfo.parameters.buttonWidth), Number(root.loaderInfo.parameters.buttonHeight));
- } catch(ex:Object) {
- this.SetButtonDimensions(0, 0);
- };
- try {
- this.SetButtonImageURL(String(root.loaderInfo.parameters.buttonImageURL));
- } catch(ex:Object) {
- this.SetButtonImageURL("");
- };
- try {
- this.SetButtonText(this.htmlEscape(String(root.loaderInfo.parameters.buttonText)));
- } catch(ex:Object) {
- this.SetButtonText("");
- };
- try {
- this.SetButtonTextPadding(Number(root.loaderInfo.parameters.buttonTextLeftPadding), Number(root.loaderInfo.parameters.buttonTextTopPadding));
- } catch(ex:Object) {
- this.SetButtonTextPadding(0, 0);
- };
- try {
- this.SetButtonTextStyle(String(root.loaderInfo.parameters.buttonTextStyle));
- } catch(ex:Object) {
- this.SetButtonTextStyle("");
- };
- try {
- this.SetButtonAction(Number(root.loaderInfo.parameters.buttonAction));
- } catch(ex:Object) {
- this.SetButtonAction(this.BUTTON_ACTION_SELECT_FILES);
- };
- try {
- this.SetButtonDisabled(((root.loaderInfo.parameters.buttonDisabled == "true")) ? true : false);
- } catch(ex:Object) {
- this.SetButtonDisabled(Boolean(false));
- };
- try {
- this.SetButtonCursor(Number(root.loaderInfo.parameters.buttonCursor));
- } catch(ex:Object) {
- this.SetButtonCursor(this.BUTTON_CURSOR_ARROW);
- };
- this.SetupExternalInterface();
- this.Debug("SWFUpload Init Complete");
- this.PrintDebugInfo();
- if (ExternalCall.Bool(this.testExternalInterface_Callback)){
- ExternalCall.Simple(this.flashReady_Callback);
- this.hasCalledFlashReady = true;
- };
- oSelf = this;
- this.restoreExtIntTimer = new Timer(1000, 0);
- this.restoreExtIntTimer.addEventListener(TimerEvent.TIMER, function ():void{
- oSelf.CheckExternalInterface();
- });
- this.restoreExtIntTimer.start();
- }
- public static function main():void{
- var _local1:SWFUpload = new (SWFUpload);
- }
- private function CheckExternalInterface():void{
- if (!ExternalCall.Bool(this.testExternalInterface_Callback)){
- this.SetupExternalInterface();
- this.Debug("ExternalInterface reinitialized");
- if (!this.hasCalledFlashReady){
- ExternalCall.Simple(this.flashReady_Callback);
- this.hasCalledFlashReady = true;
- };
- };
- }
- private function TestExternalInterface():Boolean{
- return (true);
- }
- private function SetupExternalInterface():void{
- try {
- ExternalInterface.addCallback("SelectFile", this.SelectFile);
- ExternalInterface.addCallback("SelectFiles", this.SelectFiles);
- ExternalInterface.addCallback("StartUpload", this.StartUpload);
- ExternalInterface.addCallback("ReturnUploadStart", this.ReturnUploadStart);
- ExternalInterface.addCallback("StopUpload", this.StopUpload);
- ExternalInterface.addCallback("CancelUpload", this.CancelUpload);
- ExternalInterface.addCallback("RequeueUpload", this.RequeueUpload);
- ExternalInterface.addCallback("GetStats", this.GetStats);
- ExternalInterface.addCallback("SetStats", this.SetStats);
- ExternalInterface.addCallback("GetFile", this.GetFile);
- ExternalInterface.addCallback("GetFileByIndex", this.GetFileByIndex);
- ExternalInterface.addCallback("AddFileParam", this.AddFileParam);
- ExternalInterface.addCallback("RemoveFileParam", this.RemoveFileParam);
- ExternalInterface.addCallback("SetUploadURL", this.SetUploadURL);
- ExternalInterface.addCallback("SetPostParams", this.SetPostParams);
- ExternalInterface.addCallback("SetFileTypes", this.SetFileTypes);
- ExternalInterface.addCallback("SetFileSizeLimit", this.SetFileSizeLimit);
- ExternalInterface.addCallback("SetFileUploadLimit", this.SetFileUploadLimit);
- ExternalInterface.addCallback("SetFileQueueLimit", this.SetFileQueueLimit);
- ExternalInterface.addCallback("SetFilePostName", this.SetFilePostName);
- ExternalInterface.addCallback("SetUseQueryString", this.SetUseQueryString);
- ExternalInterface.addCallback("SetRequeueOnError", this.SetRequeueOnError);
- ExternalInterface.addCallback("SetHTTPSuccess", this.SetHTTPSuccess);
- ExternalInterface.addCallback("SetAssumeSuccessTimeout", this.SetAssumeSuccessTimeout);
- ExternalInterface.addCallback("SetDebugEnabled", this.SetDebugEnabled);
- ExternalInterface.addCallback("SetButtonImageURL", this.SetButtonImageURL);
- ExternalInterface.addCallback("SetButtonDimensions", this.SetButtonDimensions);
- ExternalInterface.addCallback("SetButtonText", this.SetButtonText);
- ExternalInterface.addCallback("SetButtonTextPadding", this.SetButtonTextPadding);
- ExternalInterface.addCallback("SetButtonTextStyle", this.SetButtonTextStyle);
- ExternalInterface.addCallback("SetButtonAction", this.SetButtonAction);
- ExternalInterface.addCallback("SetButtonDisabled", this.SetButtonDisabled);
- ExternalInterface.addCallback("SetButtonCursor", this.SetButtonCursor);
- ExternalInterface.addCallback("TestExternalInterface", this.TestExternalInterface);
- } catch(ex:Error) {
- this.Debug(("Callbacks where not set: " + ex.message));
- return;
- };
- ExternalCall.Simple(this.cleanUp_Callback);
- }
- private function DialogCancelled_Handler(_arg1:Event):void{
- this.Debug("Event: fileDialogComplete: File Dialog window cancelled.");
- ExternalCall.FileDialogComplete(this.fileDialogComplete_Callback, 0, 0, this.queued_uploads);
- }
- private function Open_Handler(_arg1:Event):void{
- this.Debug(("Event: uploadProgress (OPEN): File ID: " + this.current_file_item.id));
- ExternalCall.UploadProgress(this.uploadProgress_Callback, this.current_file_item.ToJavaScriptObject(), 0, this.current_file_item.file_reference.size);
- }
- private function FileProgress_Handler(_arg1:ProgressEvent):void{
- var _local2:Number = ((_arg1.bytesLoaded < 0)) ? 0 : _arg1.bytesLoaded;
- var _local3:Number = ((_arg1.bytesTotal < 0)) ? 0 : _arg1.bytesTotal;
- if ((((((_local2 === _local3)) && ((_local3 > 0)))) && ((this.assumeSuccessTimeout > 0)))){
- if (this.assumeSuccessTimer !== null){
- this.assumeSuccessTimer.stop();
- this.assumeSuccessTimer = null;
- };
- this.assumeSuccessTimer = new Timer((this.assumeSuccessTimeout * 1000), 1);
- this.assumeSuccessTimer.addEventListener(TimerEvent.TIMER_COMPLETE, this.AssumeSuccessTimer_Handler);
- this.assumeSuccessTimer.start();
- };
- this.Debug(((((("Event: uploadProgress: File ID: " + this.current_file_item.id) + ". Bytes: ") + _local2) + ". Total: ") + _local3));
- ExternalCall.UploadProgress(this.uploadProgress_Callback, this.current_file_item.ToJavaScriptObject(), _local2, _local3);
- }
- private function AssumeSuccessTimer_Handler(_arg1:TimerEvent):void{
- this.Debug((("Event: AssumeSuccess: " + this.assumeSuccessTimeout) + " passed without server response"));
- this.UploadSuccess(this.current_file_item, "", false);
- }
- private function Complete_Handler(_arg1:Event):void{
- if (this.serverDataTimer != null){
- this.serverDataTimer.stop();
- this.serverDataTimer = null;
- };
- this.serverDataTimer = new Timer(100, 1);
- this.serverDataTimer.addEventListener(TimerEvent.TIMER, this.ServerDataTimer_Handler);
- this.serverDataTimer.start();
- }
- private function ServerDataTimer_Handler(_arg1:TimerEvent):void{
- this.UploadSuccess(this.current_file_item, "");
- }
- private function ServerData_Handler(_arg1:DataEvent):void{
- this.UploadSuccess(this.current_file_item, _arg1.data);
- }
- private function UploadSuccess(_arg1:FileItem, _arg2:String, _arg3:Boolean=true):void{
- if (this.serverDataTimer !== null){
- this.serverDataTimer.stop();
- this.serverDataTimer = null;
- };
- if (this.assumeSuccessTimer !== null){
- this.assumeSuccessTimer.stop();
- this.assumeSuccessTimer = null;
- };
- this.successful_uploads++;
- _arg1.file_status = FileItem.FILE_STATUS_SUCCESS;
- this.Debug(((((("Event: uploadSuccess: File ID: " + _arg1.id) + " Response Received: ") + _arg3.toString()) + " Data: ") + _arg2));
- ExternalCall.UploadSuccess(this.uploadSuccess_Callback, _arg1.ToJavaScriptObject(), _arg2, _arg3);
- this.UploadComplete(false);
- }
- private function HTTPError_Handler(_arg1:HTTPStatusEvent):void{
- var _local4:DataEvent;
- var _local2:Boolean;
- var _local3:Number = 0;
- while (_local3 < this.httpSuccess.length) {
- if (this.httpSuccess[_local3] === _arg1.status){
- _local2 = true;
- break;
- };
- _local3++;
- };
- if (_local2){
- this.Debug((("Event: httpError: Translating status code " + _arg1.status) + " to uploadSuccess"));
- _local4 = new DataEvent(DataEvent.UPLOAD_COMPLETE_DATA, _arg1.bubbles, _arg1.cancelable, "");
- this.ServerData_Handler(_local4);
- } else {
- this.upload_errors++;
- this.current_file_item.file_status = FileItem.FILE_STATUS_ERROR;
- this.Debug((((("Event: uploadError: HTTP ERROR : File ID: " + this.current_file_item.id) + ". HTTP Status: ") + _arg1.status) + "."));
- ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_HTTP_ERROR, this.current_file_item.ToJavaScriptObject(), _arg1.status.toString());
- this.UploadComplete(true);
- };
- }
- private function IOError_Handler(_arg1:IOErrorEvent):void{
- if (this.current_file_item.file_status != FileItem.FILE_STATUS_ERROR){
- this.upload_errors++;
- this.current_file_item.file_status = FileItem.FILE_STATUS_ERROR;
- this.Debug(((("Event: uploadError : IO Error : File ID: " + this.current_file_item.id) + ". IO Error: ") + _arg1.text));
- ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_IO_ERROR, this.current_file_item.ToJavaScriptObject(), _arg1.text);
- };
- this.UploadComplete(true);
- }
- private function SecurityError_Handler(_arg1:SecurityErrorEvent):void{
- this.upload_errors++;
- this.current_file_item.file_status = FileItem.FILE_STATUS_ERROR;
- this.Debug(((("Event: uploadError : Security Error : File Number: " + this.current_file_item.id) + ". Error text: ") + _arg1.text));
- ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_SECURITY_ERROR, this.current_file_item.ToJavaScriptObject(), _arg1.text);
- this.UploadComplete(true);
- }
- private function Select_Many_Handler(_arg1:Event):void{
- this.Select_Handler(this.fileBrowserMany.fileList);
- }
- private function Select_One_Handler(_arg1:Event):void{
- var _local2:Array = new Array(1);
- _local2[0] = this.fileBrowserOne;
- this.Select_Handler(_local2);
- }
- private function Select_Handler(_arg1:Array):void{
- var _local4:Number;
- var _local5:Number;
- var _local6:FileItem;
- var _local7:Object;
- var _local8:Boolean;
- var _local9:Number;
- var _local10:Boolean;
- this.Debug("Select Handler: Received the files selected from the dialog. Processing the file list...");
- var _local2:Number = 0;
- var _local3:Number = 0;
- if (this.fileUploadLimit == 0){
- _local3 = ((this.fileQueueLimit == 0)) ? _arg1.length : (this.fileQueueLimit - this.queued_uploads);
- } else {
- _local4 = ((this.fileUploadLimit - this.successful_uploads) - this.queued_uploads);
- if (_local4 < 0){
- _local4 = 0;
- };
- if ((((this.fileQueueLimit == 0)) || ((this.fileQueueLimit >= _local4)))){
- _local3 = _local4;
- } else {
- if (this.fileQueueLimit < _local4){
- _local3 = (this.fileQueueLimit - this.queued_uploads);
- };
- };
- };
- if (_local3 < 0){
- _local3 = 0;
- };
- if (_local3 < _arg1.length){
- this.Debug((((("Event: fileQueueError : Selected Files (" + _arg1.length) + ") exceeds remaining Queue size (") + _local3) + ")."));
- ExternalCall.FileQueueError(this.fileQueueError_Callback, this.ERROR_CODE_QUEUE_LIMIT_EXCEEDED, null, _local3.toString());
- } else {
- _local5 = 0;
- while (_local5 < _arg1.length) {
- _local6 = new FileItem(_arg1[_local5], this.movieName, this.file_index.length);
- this.file_index[_local6.index] = _local6;
- _local7 = _local6.ToJavaScriptObject();
- _local8 = !((_local7.filestatus === FileItem.FILE_STATUS_ERROR));
- if (_local8){
- _local9 = this.CheckFileSize(_local6);
- _local10 = this.CheckFileType(_local6);
- if ((((_local9 == this.SIZE_OK)) && (_local10))){
- _local6.file_status = FileItem.FILE_STATUS_QUEUED;
- this.file_queue.push(_local6);
- this.queued_uploads++;
- _local2++;
- this.Debug(("Event: fileQueued : File ID: " + _local6.id));
- ExternalCall.FileQueued(this.fileQueued_Callback, _local6.ToJavaScriptObject());
- } else {
- if (!_local10){
- _local6.file_reference = null;
- this.queue_errors++;
- this.Debug("Event: fileQueueError : File not of a valid type.");
- ExternalCall.FileQueueError(this.fileQueueError_Callback, this.ERROR_CODE_INVALID_FILETYPE, _local6.ToJavaScriptObject(), "File is not an allowed file type.");
- } else {
- if (_local9 == this.SIZE_TOO_BIG){
- _local6.file_reference = null;
- this.queue_errors++;
- this.Debug("Event: fileQueueError : File exceeds size limit.");
- ExternalCall.FileQueueError(this.fileQueueError_Callback, this.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT, _local6.ToJavaScriptObject(), "File size exceeds allowed limit.");
- } else {
- if (_local9 == this.SIZE_ZERO_BYTE){
- _local6.file_reference = null;
- this.queue_errors++;
- this.Debug("Event: fileQueueError : File is zero bytes.");
- ExternalCall.FileQueueError(this.fileQueueError_Callback, this.ERROR_CODE_ZERO_BYTE_FILE, _local6.ToJavaScriptObject(), "File is zero bytes and cannot be uploaded.");
- };
- };
- };
- };
- } else {
- _local6.file_reference = null;
- this.queue_errors++;
- this.Debug("Event: fileQueueError : File is zero bytes or FileReference is invalid.");
- ExternalCall.FileQueueError(this.fileQueueError_Callback, this.ERROR_CODE_ZERO_BYTE_FILE, _local6.ToJavaScriptObject(), "File is zero bytes or cannot be accessed and cannot be uploaded.");
- };
- _local5++;
- };
- };
- this.Debug(((("Event: fileDialogComplete : Finished processing selected files. Files selected: " + _arg1.length) + ". Files Queued: ") + _local2));
- ExternalCall.FileDialogComplete(this.fileDialogComplete_Callback, _arg1.length, _local2, this.queued_uploads);
- }
- private function SelectFile():void{
- this.fileBrowserOne = new FileReference();
- this.fileBrowserOne.addEventListener(Event.SELECT, this.Select_One_Handler);
- this.fileBrowserOne.addEventListener(Event.CANCEL, this.DialogCancelled_Handler);
- var allowed_file_types:* = "*.*";
- var allowed_file_types_description:* = "All Files";
- if (this.fileTypes.length > 0){
- allowed_file_types = this.fileTypes;
- };
- if (this.fileTypesDescription.length > 0){
- allowed_file_types_description = this.fileTypesDescription;
- };
- this.Debug(("Event: fileDialogStart : Browsing files. Single Select. Allowed file types: " + allowed_file_types));
- ExternalCall.Simple(this.fileDialogStart_Callback);
- try {
- this.fileBrowserOne.browse([new FileFilter(allowed_file_types_description, allowed_file_types)]);
- } catch(ex:Error) {
- this.Debug(("Exception: " + ex.toString()));
- };
- }
- private function SelectFiles():void{
- var allowed_file_types:* = "*.*";
- var allowed_file_types_description:* = "All Files";
- if (this.fileTypes.length > 0){
- allowed_file_types = this.fileTypes;
- };
- if (this.fileTypesDescription.length > 0){
- allowed_file_types_description = this.fileTypesDescription;
- };
- this.Debug(("Event: fileDialogStart : Browsing files. Multi Select. Allowed file types: " + allowed_file_types));
- ExternalCall.Simple(this.fileDialogStart_Callback);
- try {
- this.fileBrowserMany.browse([new FileFilter(allowed_file_types_description, allowed_file_types)]);
- } catch(ex:Error) {
- this.Debug(("Exception: " + ex.toString()));
- };
- }
- private function StopUpload():void{
- var _local1:Object;
- if (this.current_file_item != null){
- this.current_file_item.file_reference.cancel();
- this.removeFileReferenceEventListeners(this.current_file_item);
- this.current_file_item.file_status = FileItem.FILE_STATUS_QUEUED;
- this.file_queue.unshift(this.current_file_item);
- _local1 = this.current_file_item.ToJavaScriptObject();
- this.current_file_item = null;
- this.Debug(("Event: uploadError: upload stopped. File ID: " + _local1.ID));
- ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_UPLOAD_STOPPED, _local1, "Upload Stopped");
- this.Debug(("Event: uploadComplete. File ID: " + _local1.ID));
- ExternalCall.UploadComplete(this.uploadComplete_Callback, _local1);
- this.Debug("StopUpload(): upload stopped.");
- } else {
- this.Debug("StopUpload(): No file is currently uploading. Nothing to do.");
- };
- }
- private function CancelUpload(_arg1:String, _arg2:Boolean=true):void{
- var _local4:Number;
- var _local3:FileItem;
- if (((!((this.current_file_item == null))) && ((((this.current_file_item.id == _arg1)) || (!(_arg1)))))){
- this.current_file_item.file_reference.cancel();
- this.current_file_item.file_status = FileItem.FILE_STATUS_CANCELLED;
- this.upload_cancelled++;
- if (_arg2){
- this.Debug((("Event: uploadError: File ID: " + this.current_file_item.id) + ". Cancelled current upload"));
- ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_FILE_CANCELLED, this.current_file_item.ToJavaScriptObject(), "File Upload Cancelled.");
- } else {
- this.Debug((("Event: cancelUpload: File ID: " + this.current_file_item.id) + ". Cancelled current upload. Suppressed uploadError event."));
- };
- this.UploadComplete(false);
- } else {
- if (_arg1){
- _local4 = this.FindIndexInFileQueue(_arg1);
- if (_local4 >= 0){
- _local3 = FileItem(this.file_queue[_local4]);
- _local3.file_status = FileItem.FILE_STATUS_CANCELLED;
- this.file_queue[_local4] = null;
- this.queued_uploads--;
- this.upload_cancelled++;
- _local3.file_reference.cancel();
- this.removeFileReferenceEventListeners(_local3);
- _local3.file_reference = null;
- if (_arg2){
- this.Debug((("Event: uploadError : " + _local3.id) + ". Cancelled queued upload"));
- ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_FILE_CANCELLED, _local3.ToJavaScriptObject(), "File Cancelled");
- } else {
- this.Debug((("Event: cancelUpload: File ID: " + _local3.id) + ". Cancelled current upload. Suppressed uploadError event."));
- };
- _local3 = null;
- };
- } else {
- while ((((this.file_queue.length > 0)) && ((_local3 == null)))) {
- _local3 = FileItem(this.file_queue.shift());
- if (typeof(_local3) == "undefined"){
- _local3 = null;
- };
- };
- if (_local3 != null){
- _local3.file_status = FileItem.FILE_STATUS_CANCELLED;
- this.queued_uploads--;
- this.upload_cancelled++;
- _local3.file_reference.cancel();
- this.removeFileReferenceEventListeners(_local3);
- _local3.file_reference = null;
- if (_arg2){
- this.Debug((("Event: uploadError : " + _local3.id) + ". Cancelled queued upload"));
- ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_FILE_CANCELLED, _local3.ToJavaScriptObject(), "File Cancelled");
- } else {
- this.Debug((("Event: cancelUpload: File ID: " + _local3.id) + ". Cancelled current upload. Suppressed uploadError event."));
- };
- _local3 = null;
- };
- };
- };
- }
- private function RequeueUpload(_arg1):Boolean{
- var _local3:Number;
- var _local2:FileItem;
- if (typeof(_arg1) === "number"){
- _local3 = Number(_arg1);
- if ((((_local3 >= 0)) && ((_local3 < this.file_index.length)))){
- _local2 = this.file_index[_local3];
- };
- } else {
- if (typeof(_arg1) === "string"){
- _local2 = this.FindFileInFileIndex(String(_arg1));
- } else {
- return (false);
- };
- };
- if (_local2 !== null){
- if ((((_local2.file_status === FileItem.FILE_STATUS_IN_PROGRESS)) || ((_local2.file_status === FileItem.FILE_STATUS_NEW)))){
- return (false);
- };
- if (_local2.file_status !== FileItem.FILE_STATUS_QUEUED){
- _local2.file_status = FileItem.FILE_STATUS_QUEUED;
- this.file_queue.unshift(_local2);
- this.queued_uploads++;
- };
- return (true);
- };
- return (false);
- }
- private function GetStats():Object{
- return ({
- in_progress:((this.current_file_item == null)) ? 0 : 1,
- files_queued:this.queued_uploads,
- successful_uploads:this.successful_uploads,
- upload_errors:this.upload_errors,
- upload_cancelled:this.upload_cancelled,
- queue_errors:this.queue_errors
- });
- }
- private function SetStats(_arg1:Object):void{
- this.successful_uploads = ((typeof(_arg1["successful_uploads"]) === "number")) ? _arg1["successful_uploads"] : this.successful_uploads;
- this.upload_errors = ((typeof(_arg1["upload_errors"]) === "number")) ? _arg1["upload_errors"] : this.upload_errors;
- this.upload_cancelled = ((typeof(_arg1["upload_cancelled"]) === "number")) ? _arg1["upload_cancelled"] : this.upload_cancelled;
- this.queue_errors = ((typeof(_arg1["queue_errors"]) === "number")) ? _arg1["queue_errors"] : this.queue_errors;
- }
- private function GetFile(_arg1:String):Object{
- var _local3:FileItem;
- var _local4:Number;
- var _local2:Number = this.FindIndexInFileQueue(_arg1);
- if (_local2 >= 0){
- _local3 = this.file_queue[_local2];
- } else {
- if (this.current_file_item != null){
- _local3 = this.current_file_item;
- } else {
- _local4 = 0;
- while (_local4 < this.file_queue.length) {
- _local3 = this.file_queue[_local4];
- if (_local3 != null){
- break;
- };
- _local4++;
- };
- };
- };
- if (_local3 == null){
- return (null);
- };
- return (_local3.ToJavaScriptObject());
- }
- private function GetFileByIndex(_arg1:Number):Object{
- if ((((_arg1 < 0)) || ((_arg1 > (this.file_index.length - 1))))){
- return (null);
- };
- return (this.file_index[_arg1].ToJavaScriptObject());
- }
- private function AddFileParam(_arg1:String, _arg2:String, _arg3:String):Boolean{
- var _local4:FileItem = this.FindFileInFileIndex(_arg1);
- if (_local4 != null){
- _local4.AddParam(_arg2, _arg3);
- return (true);
- };
- return (false);
- }
- private function RemoveFileParam(_arg1:String, _arg2:String):Boolean{
- var _local3:FileItem = this.FindFileInFileIndex(_arg1);
- if (_local3 != null){
- _local3.RemoveParam(_arg2);
- return (true);
- };
- return (false);
- }
- private function SetUploadURL(_arg1:String):void{
- if (((!(("string" === "undefined"))) && (!((_arg1 === ""))))){
- this.uploadURL = _arg1;
- };
- }
- private function SetPostParams(_arg1:Object):void{
- if (((!((typeof(_arg1) === "undefined"))) && (!((_arg1 === null))))){
- this.uploadPostObject = _arg1;
- };
- }
- private function SetFileTypes(_arg1:String, _arg2:String):void{
- this.fileTypes = _arg1;
- this.fileTypesDescription = _arg2;
- this.LoadFileExensions(this.fileTypes);
- }
- private function SetFileSizeLimit(_arg1:String):void{
- var _local2:Number = 0;
- var _local3 = "kb";
- var _local4:RegExp = /^\s*|\s*$/;
- _arg1 = _arg1.toLowerCase();
- _arg1 = _arg1.replace(_local4, "");
- var _local5:Array = _arg1.match(/^\d+/);
- if (((!((_local5 === null))) && ((_local5.length > 0)))){
- _local2 = parseInt(_local5[0]);
- };
- if (((isNaN(_local2)) || ((_local2 < 0)))){
- _local2 = 0;
- };
- var _local6:Array = _arg1.match(/(b|kb|mb|gb)/);
- if (((!((_local6 == null))) && ((_local6.length > 0)))){
- _local3 = _local6[0];
- };
- var _local7:Number = 0x0400;
- if (_local3 === "b"){
- _local7 = 1;
- } else {
- if (_local3 === "mb"){
- _local7 = 0x100000;
- } else {
- if (_local3 === "gb"){
- _local7 = 1073741824;
- };
- };
- };
- this.fileSizeLimit = (_local2 * _local7);
- }
- private function SetFileUploadLimit(_arg1:Number):void{
- if (_arg1 < 0){
- _arg1 = 0;
- };
- this.fileUploadLimit = _arg1;
- }
- private function SetFileQueueLimit(_arg1:Number):void{
- if (_arg1 < 0){
- _arg1 = 0;
- };
- this.fileQueueLimit = _arg1;
- }
- private function SetFilePostName(_arg1:String):void{
- if (_arg1 != ""){
- this.filePostName = _arg1;
- };
- }
- private function SetUseQueryString(_arg1:Boolean):void{
- this.useQueryString = _arg1;
- }
- private function SetRequeueOnError(_arg1:Boolean):void{
- this.requeueOnError = _arg1;
- }
- private function SetHTTPSuccess(_arg1):void{
- var status_code_strings:* = null;
- var http_status_string:* = null;
- var http_status:* = undefined;
- var http_status_codes:* = _arg1;
- this.httpSuccess = [];
- if (typeof(http_status_codes) === "string"){
- status_code_strings = http_status_codes.replace(" ", "").split(",");
- for each (http_status_string in status_code_strings) {
- try {
- this.httpSuccess.push(Number(http_status_string));
- } catch(ex:Object) {
- this.Debug(("Could not add HTTP Success code: " + http_status_string));
- };
- };
- } else {
- if ((((typeof(http_status_codes) === "object")) && ((typeof(http_status_codes.length) === "number")))){
- for each (http_status in http_status_codes) {
- try {
- this.Debug(("adding: " + http_status));
- this.httpSuccess.push(Number(http_status));
- } catch(ex:Object) {
- this.Debug(("Could not add HTTP Success code: " + http_status));
- };
- };
- };
- };
- }
- private function SetAssumeSuccessTimeout(_arg1:Number):void{
- this.assumeSuccessTimeout = ((_arg1 < 0)) ? 0 : _arg1;
- }
- private function SetDebugEnabled(_arg1:Boolean):void{
- this.debugEnabled = _arg1;
- }
- private function SetButtonImageURL(_arg1:String):void{
- this.buttonImageURL = _arg1;
- try {
- if (((!((this.buttonImageURL === null))) && (!((this.buttonImageURL === ""))))){
- this.buttonLoader.load(new URLRequest(this.buttonImageURL));
- };
- } catch(ex:Object) {
- };
- }
- private function ButtonClickHandler(_arg1:MouseEvent):void{
- if (!this.buttonStateDisabled){
- if (this.buttonAction === this.BUTTON_ACTION_SELECT_FILE){
- this.SelectFile();
- } else {
- if (this.buttonAction === this.BUTTON_ACTION_START_UPLOAD){
- this.StartUpload();
- } else {
- this.SelectFiles();
- };
- };
- };
- }
- private function UpdateButtonState():void{
- var _local1:Number = 0;
- var _local2:Number = 0;
- this.buttonLoader.x = _local1;
- this.buttonLoader.y = _local2;
- if (this.buttonStateDisabled){
- this.buttonLoader.y = ((this.buttonHeight * -3) + _local2);
- } else {
- if (this.buttonStateMouseDown){
- this.buttonLoader.y = ((this.buttonHeight * -2) + _local2);
- } else {
- if (this.buttonStateOver){
- this.buttonLoader.y = ((this.buttonHeight * -1) + _local2);
- } else {
- this.buttonLoader.y = -(_local2);
- };
- };
- };
- }
- private function SetButtonDimensions(_arg1:Number=-1, _arg2:Number=-1):void{
- if (_arg1 >= 0){
- this.buttonWidth = _arg1;
- };
- if (_arg2 >= 0){
- this.buttonHeight = _arg2;
- };
- this.buttonTextField.width = this.buttonWidth;
- this.buttonTextField.height = this.buttonHeight;
- this.buttonCursorSprite.width = this.buttonWidth;
- this.buttonCursorSprite.height = this.buttonHeight;
- this.UpdateButtonState();
- }
- private function SetButtonText(_arg1:String):void{
- this.buttonText = _arg1;
- this.SetButtonTextStyle(this.buttonTextStyle);
- }
- private function SetButtonTextStyle(_arg1:String):void{
- this.buttonTextStyle = _arg1;
- var _local2:StyleSheet = new StyleSheet();
- _local2.parseCSS(this.buttonTextStyle);
- this.buttonTextField.styleSheet = _local2;
- this.buttonTextField.htmlText = (("<span class=\"button-text\">" + this.buttonText) + "</span>");
- }
- private function SetButtonTextPadding(_arg1:Number, _arg2:Number):void{
- this.buttonTextField.x = (this.buttonTextLeftPadding = _arg1);
- this.buttonTextField.y = (this.buttonTextTopPadding = _arg2);
- }
- private function SetButtonDisabled(_arg1:Boolean):void{
- this.buttonStateDisabled = _arg1;
- this.UpdateButtonState();
- }
- private function SetButtonAction(_arg1:Number):void{
- this.buttonAction = _arg1;
- }
- private function SetButtonCursor(_arg1:Number):void{
- this.buttonCursor = _arg1;
- this.buttonCursorSprite.useHandCursor = (_arg1 === this.BUTTON_CURSOR_HAND);
- }
- private function StartUpload(_arg1:String=""):void{
- var _local2:Number;
- if (this.current_file_item != null){
- this.Debug("StartUpload(): Upload already in progress. Not starting another upload.");
- return;
- };
- this.Debug(("StartUpload: " + (_arg1) ? ("File ID: " + _arg1) : "First file in queue"));
- if ((((this.successful_uploads >= this.fileUploadLimit)) && (!((this.fileUploadLimit == 0))))){
- this.Debug("Event: uploadError : Upload limit reached. No more files can be uploaded.");
- ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_UPLOAD_LIMIT_EXCEEDED, null, "The upload limit has been reached.");
- this.current_file_item = null;
- return;
- };
- if (!_arg1){
- while ((((this.file_queue.length > 0)) && ((this.current_file_item == null)))) {
- this.current_file_item = FileItem(this.file_queue.shift());
- if (typeof(this.current_file_item) == "undefined"){
- this.current_file_item = null;
- };
- };
- } else {
- _local2 = this.FindIndexInFileQueue(_arg1);
- if (_local2 >= 0){
- this.current_file_item = FileItem(this.file_queue[_local2]);
- this.file_queue[_local2] = null;
- } else {
- this.Debug(("Event: uploadError : File ID not found in queue: " + _arg1));
- ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_SPECIFIED_FILE_ID_NOT_FOUND, null, "File ID not found in the queue.");
- };
- };
- if (this.current_file_item != null){
- this.Debug(("Event: uploadStart : File ID: " + this.current_file_item.id));
- this.current_file_item.file_status = FileItem.FILE_STATUS_IN_PROGRESS;
- ExternalCall.UploadStart(this.uploadStart_Callback, this.current_file_item.ToJavaScriptObject());
- } else {
- this.Debug("StartUpload(): No files found in the queue.");
- };
- }
- private function ReturnUploadStart(_arg1:Boolean):void{
- var js_object:* = null;
- var request:* = null;
- var message:* = null;
- var start_upload:* = _arg1;
- if (this.current_file_item == null){
- this.Debug("ReturnUploadStart called but no file was prepped for uploading. The file may have been cancelled or stopped.");
- return;
- };
- if (start_upload){
- try {
- this.current_file_item.file_reference.addEventListener(Event.OPEN, this.Open_Handler);
- this.current_file_item.file_reference.addEventListener(ProgressEvent.PROGRESS, this.FileProgress_Handler);
- this.current_file_item.file_reference.addEventListener(IOErrorEvent.IO_ERROR, this.IOError_Handler);
- this.current_file_item.file_reference.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.SecurityError_Handler);
- this.current_file_item.file_reference.addEventListener(HTTPStatusEvent.HTTP_STATUS, this.HTTPError_Handler);
- this.current_file_item.file_reference.addEventListener(Event.COMPLETE, this.Complete_Handler);
- this.current_file_item.file_reference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, this.ServerData_Handler);
- request = this.BuildRequest();
- if (this.uploadURL.length == 0){
- this.Debug((("Event: uploadError : IO Error : File ID: " + this.current_file_item.id) + ". Upload URL string is empty."));
- this.removeFileReferenceEventListeners(this.current_file_item);
- this.current_file_item.file_status = FileItem.FILE_STATUS_QUEUED;
- this.file_queue.unshift(this.current_file_item);
- js_object = this.current_file_item.ToJavaScriptObject();
- this.current_file_item = null;
- ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_MISSING_UPLOAD_URL, js_object, "Upload URL string is empty.");
- } else {
- this.Debug(((("ReturnUploadStart(): File accepted by startUpload event and readied for upload. Starting upload to " + request.url) + " for File ID: ") + this.current_file_item.id));
- this.current_file_item.file_status = FileItem.FILE_STATUS_IN_PROGRESS;
- this.current_file_item.file_reference.upload(request, this.filePostName, false);
- };
- } catch(ex:Error) {
- this.Debug(("ReturnUploadStart: Exception occurred: " + message));
- this.upload_errors++;
- this.current_file_item.file_status = FileItem.FILE_STATUS_ERROR;
- message = ((((((ex.errorID + "\n") + ex.name) + "\n") + ex.message) + "\n") + ex.getStackTrace());
- this.Debug(("Event: uploadError(): Upload Failed. Exception occurred: " + message));
- ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_UPLOAD_FAILED, this.current_file_item.ToJavaScriptObject(), message);
- this.UploadComplete(true);
- };
- } else {
- this.removeFileReferenceEventListeners(this.current_file_item);
- this.current_file_item.file_status = FileItem.FILE_STATUS_QUEUED;
- js_object = this.current_file_item.ToJavaScriptObject();
- this.file_queue.unshift(this.current_file_item);
- this.current_file_item = null;
- this.Debug("Event: uploadError : Call to uploadStart returned false. Not uploading the file.");
- ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_FILE_VALIDATION_FAILED, js_object, "Call to uploadStart return false. Not uploading file.");
- this.Debug("Event: uploadComplete : Call to uploadStart returned false. Not uploading the file.");
- ExternalCall.UploadComplete(this.uploadComplete_Callback, js_object);
- };
- }
- private function UploadComplete(_arg1:Boolean):void{
- var _local2:Object = this.current_file_item.ToJavaScriptObject();
- this.removeFileReferenceEventListeners(this.current_file_item);
- if (((!(_arg1)) || ((this.requeueOnError == false)))){
- this.current_file_item.file_reference = null;
- this.queued_uploads--;
- } else {
- if (this.requeueOnError == true){
- this.current_file_item.file_status = FileItem.FILE_STATUS_QUEUED;
- this.file_queue.unshift(this.current_file_item);
- };
- };
- this.current_file_item = null;
- this.Debug("Event: uploadComplete : Upload cycle complete.");
- ExternalCall.UploadComplete(this.uploadComplete_Callback, _local2);
- }
- private function CheckFileSize(_arg1:FileItem):Number{
- if (_arg1.file_reference.size == 0){
- return (this.SIZE_ZERO_BYTE);
- };
- if (((!((this.fileSizeLimit == 0))) && ((_arg1.file_reference.size > this.fileSizeLimit)))){
- return (this.SIZE_TOO_BIG);
- };
- return (this.SIZE_OK);
- }
- private function CheckFileType(_arg1:FileItem):Boolean{
- if (this.valid_file_extensions.length == 0){
- return (true);
- };
- var _local2:FileReference = _arg1.file_reference;
- var _local3:Number = _local2.name.lastIndexOf(".");
- var _local4 = "";
- if (_local3 >= 0){
- _local4 = _local2.name.substr((_local3 + 1)).toLowerCase();
- };
- var _local5:Boolean;
- var _local6:Number = 0;
- while (_local6 < this.valid_file_extensions.length) {
- if (String(this.valid_file_extensions[_local6]) == _local4){
- _local5 = true;
- break;
- };
- _local6++;
- };
- return (_local5);
- }
- private function BuildRequest():URLRequest{
- var _local3:Array;
- var _local4:String;
- var _local5:URLVariables;
- var _local1:URLRequest = new URLRequest();
- _local1.method = URLRequestMethod.POST;
- var _local2:Object = this.current_file_item.GetPostObject();
- if (this.useQueryString){
- _local3 = new Array();
- for (_local4 in this.uploadPostObject) {
- this.Debug(((("Global URL Item: " + _local4) + "=") + this.uploadPostObject[_local4]));
- if (this.uploadPostObject.hasOwnProperty(_local4)){
- _local3.push(((escape(_local4) + "=") + escape(this.uploadPostObject[_local4])));
- };
- };
- for (_local4 in _local2) {
- this.Debug(((("File Post Item: " + _local4) + "=") + _local2[_local4]));
- if (_local2.hasOwnProperty(_local4)){
- _local3.push(((escape(_local4) + "=") + escape(_local2[_local4])));
- };
- };
- _local1.url = ((this.uploadURL + ((this.uploadURL.indexOf("?") > -1)) ? "&" : "?") + _local3.join("&"));
- } else {
- _local5 = new URLVariables();
- for (_local4 in this.uploadPostObject) {
- this.Debug(((("Global Post Item: " + _local4) + "=") + this.uploadPostObject[_local4]));
- if (this.uploadPostObject.hasOwnProperty(_local4)){
- _local5[_local4] = this.uploadPostObject[_local4];
- };
- };
- for (_local4 in _local2) {
- this.Debug(((("File Post Item: " + _local4) + "=") + _local2[_local4]));
- if (_local2.hasOwnProperty(_local4)){
- _local5[_local4] = _local2[_local4];
- };
- };
- _local1.url = this.uploadURL;
- _local1.data = _local5;
- };
- return (_local1);
- }
- private function Debug(_arg1:String):void{
- var lines:* = null;
- var i:* = NaN;
- var msg:* = _arg1;
- try {
- if (this.debugEnabled){
- lines = msg.split("\n");
- i = 0;
- while (i < lines.length) {
- lines[i] = ("SWF DEBUG: " + lines[i]);
- i = (i + 1);
- };
- ExternalCall.Debug(this.debug_Callback, lines.join("\n"));
- };
- } catch(ex:Error) {
- };
- }
- private function PrintDebugInfo():void{
- var _local2:String;
- var _local1 = "\n----- SWF DEBUG OUTPUT ----\n";
- _local1 = (_local1 + (("Build Number: " + this.build_number) + "\n"));
- _local1 = (_local1 + (("movieName: " + this.movieName) + "\n"));
- _local1 = (_local1 + (("Upload URL: " + this.uploadURL) + "\n"));
- _local1 = (_local1 + (("File Types String: " + this.fileTypes) + "\n"));
- _local1 = (_local1 + (("Parsed File Types: " + this.valid_file_extensions.toString()) + "\n"));
- _local1 = (_local1 + (("HTTP Success: " + this.httpSuccess.join(", ")) + "\n"));
- _local1 = (_local1 + (("File Types Description: " + this.fileTypesDescription) + "\n"));
- _local1 = (_local1 + (("File Size Limit: " + this.fileSizeLimit) + " bytes\n"));
- _local1 = (_local1 + (("File Upload Limit: " + this.fileUploadLimit) + "\n"));
- _local1 = (_local1 + (("File Queue Limit: " + this.fileQueueLimit) + "\n"));
- _local1 = (_local1 + "Post Params:\n");
- for (_local2 in this.uploadPostObject) {
- if (this.uploadPostObject.hasOwnProperty(_local2)){
- _local1 = (_local1 + ((((" " + _local2) + "=") + this.uploadPostObject[_local2]) + "\n"));
- };
- };
- _local1 = (_local1 + "----- END SWF DEBUG OUTPUT ----\n");
- this.Debug(_local1);
- }
- private function FindIndexInFileQueue(_arg1:String):Number{
- var _local3:FileItem;
- var _local2:Number = 0;
- while (_local2 < this.file_queue.length) {
- _local3 = this.file_queue[_local2];
- if (((!((_local3 == null))) && ((_local3.id == _arg1)))){
- return (_local2);
- };
- _local2++;
- };
- return (-1);
- }
- private function FindFileInFileIndex(_arg1:String):FileItem{
- var _local3:FileItem;
- var _local2:Number = 0;
- while (_local2 < this.file_index.length) {
- _local3 = this.file_index[_local2];
- if (((!((_local3 == null))) && ((_local3.id == _arg1)))){
- return (_local3);
- };
- _local2++;
- };
- return (null);
- }
- private function LoadFileExensions(_arg1:String):void{
- var _local4:String;
- var _local5:Number;
- var _local2:Array = _arg1.split(";");
- this.valid_file_extensions = new Array();
- var _local3:Number = 0;
- while (_local3 < _local2.length) {
- _local4 = String(_local2[_local3]);
- _local5 = _local4.lastIndexOf(".");
- if (_local5 >= 0){
- _local4 = _local4.substr((_local5 + 1)).toLowerCase();
- } else {
- _local4 = _local4.toLowerCase();
- };
- if (_local4 == "*"){
- this.valid_file_extensions = new Array();
- break;
- };
- this.valid_file_extensions.push(_local4);
- _local3++;
- };
- }
- private function loadPostParams(_arg1:String):void{
- var _local3:Array;
- var _local4:Number;
- var _local5:String;
- var _local6:Number;
- var _local2:Object = {};
- if (_arg1 != null){
- _local3 = _arg1.split("&");
- _local4 = 0;
- while (_local4 < _local3.length) {
- _local5 = String(_local3[_local4]);
- _local6 = _local5.indexOf("=");
- if (_local6 > 0){
- _local2[decodeURIComponent(_local5.substring(0, _local6))] = decodeURIComponent(_local5.substr((_local6 + 1)));
- };
- _local4++;
- };
- };
- this.uploadPostObject = _local2;
- }
- private function removeFileReferenceEventListeners(_arg1:FileItem):void{
- if (((!((_arg1 == null))) && (!((_arg1.file_reference == null))))){
- _arg1.file_reference.removeEventListener(Event.OPEN, this.Open_Handler);
- _arg1.file_reference.removeEventListener(ProgressEvent.PROGRESS, this.FileProgress_Handler);
- _arg1.file_reference.removeEventListener(IOErrorEvent.IO_ERROR, this.IOError_Handler);
- _arg1.file_reference.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, this.SecurityError_Handler);
- _arg1.file_reference.removeEventListener(HTTPStatusEvent.HTTP_STATUS, this.HTTPError_Handler);
- _arg1.file_reference.removeEventListener(DataEvent.UPLOAD_COMPLETE_DATA, this.ServerData_Handler);
- };
- }
- public function htmlEscape(_arg1:String):String{
- return (XML(new XMLNode(XMLNodeType.TEXT_NODE, _arg1)).toXMLString());
- }
- }
- }//package
Add Comment
Please, Sign In to add comment