Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mega.fileuploader {
- import flash.net.*;
- public class File {
- private var _fileRef:FileReference;
- private var _id:string;
- private var _server:string;
- private var _description:string = "";
- private var _password:string = "";
- private var _trafficExchange:string = "";
- private var _recipientEmail:string = "";
- private var _uploaderEmail:string = "";
- private var _multiple:string = "";
- private var _hotlink:string = "0";
- public function File(_arg1:FileReference, _arg2:string){
- this._fileRef = _arg1;
- this._server = _arg2;
- this._id = this.generateRandomID(32);
- }
- public function getFileReference():FileReference{
- return (this._fileRef);
- }
- public function getsize():number{
- return (this._fileRef.size);
- }
- public function getName():string{
- return (this._fileRef.name);
- }
- public function getID():string{
- return (this._id);
- }
- public function setDescription(_arg1:string):void{
- this._description = _arg1;
- }
- public function getDescription():string{
- return (this._description);
- }
- public function setPassword(_arg1:string):void{
- this._password = _arg1;
- }
- public function getPassword():string{
- return (this._password);
- }
- public function setTrafficExchange(_arg1:string):void{
- this._trafficExchange = _arg1;
- }
- public function getTrafficExchange():string{
- return (this._trafficExchange);
- }
- public function setRecipientEmail(_arg1:string):void{
- this._recipientEmail = _arg1;
- }
- public function getRecipientEmail():string{
- return (this._recipientEmail);
- }
- public function setUploaderEmail(_arg1:string):void{
- this._uploaderEmail = _arg1;
- }
- public function getUploaderEmail():string{
- return (this._uploaderEmail);
- }
- public function setMultipleRecipients(_arg1:string):void{
- this._multiple = _arg1;
- }
- public function getMultipleRecipients():string{
- return (this._multiple);
- }
- public function setHotlink(_arg1:string):void{
- this._hotlink = _arg1;
- }
- public function getHotlink():string{
- return (this._hotlink);
- }
- public function setServer(_arg1:string):void{
- this._server = _arg1;
- }
- public function getServer():string{
- return (this._server);
- }
- private function generateRandomID(_arg1:number):string{
- var _local7:string;
- var _local2:array = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];
- var _local3 = "0";
- var _local4:string = (_local3 + new date().gettime());
- var _local5:uint = (_arg1 - _local4.length);
- var _local6:uint = 1;
- while (_local6 <= _local5) {
- _local7 = _local2[math.floor((math.random() * 10))];
- _local4 = (_local4 + _local7);
- _local6++;
- };
- return (_local4);
- }
- }
- }//package com.mega.fileuploader
- package com.mega.fileuploader {
- import __AS3__.vec.*;
- import flash.events.*;
- import flash.net.*;
- import flash.display.*;
- import flash.utils.*;
- import flash.external.*;
- import flash.errors.*;
- public class FileUploader extends Sprite {
- private static const TIME_OUT_TIME:number = 60000;
- private static const STATUS_FILE_SELECT:string = "fileSelect";
- private static const STATUS_UPLOADING:string = "uploading";
- private static const STATUS_FINISHED:string = "finished";
- private var _fileRefList:FileReferenceList;
- private var _allFiles:Vector.<File>;
- private var _serverList:Vector.<String>;
- private var _processedFileIndex:number = 0;
- private var _timeOutTimer:Timer;
- private var _button:Sprite;
- private var _clickCount:uint = 0;
- private var _lastProgressTime:number;
- private var _status:string;
- private var _userID:string;
- public function FileUploader(){
- stage.align = StageAlign.TOP_LEFT;
- stage.scalemode = StageScaleMode.NO_SCALE;
- stage.showDefaultContextMenu = false;
- this._status = STATUS_FILE_SELECT;
- this._timeOutTimer = new Timer(500);
- this._timeOutTimer.addEventListener(TimerEvent.TIMER, this.timeOutTick);
- this._allFiles = new Vector.<File>();
- var _local1:string = ((this.root.loaderInfo.parameters.servers)==undefined) ? "http%3A%2F%2Fwww173.megaupload.com%2F" : this.root.loaderInfo.parameters.servers;
- this._serverList = this.getServerList(_local1);
- this._userID = ((this.root.loaderInfo.parameters.user)==undefined) ? "" : this.root.loaderInfo.parameters.user;
- this._fileRefList = new FileReferenceList();
- this._fileRefList.addEventListener(Event.SELECT, this.filesSelectedHandler);
- this.registerCallbacks();
- stage.addEventListener(MouseEvent.CLICK, this.browseHandler);
- }
- private function getServerList(_arg1:string):Vector.<String>{
- var _local3:uint;
- var _local2:array = _arg1.split(";");
- while (_local3 < _local2.length) {
- _local2[_local3] = decodeURIComponent(_local2[_local3]);
- _local3++;
- };
- return (Vector.<String>(_local2));
- }
- private function createButton():void{
- this._button = new Sprite();
- this._button.graphics.beginfill(0, 0);
- this._button.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
- this._button.graphics.endfill();
- this._button.addEventListener(MouseEvent.CLICK, this.browseHandler);
- this._button.mouseChildren = false;
- this._button.buttonMode = true;
- addChild(this._button);
- }
- private function browseHandler(_arg1:MouseEvent):void{
- this._fileRefList.browse();
- }
- private function stageResizeHandler(_arg1:Event):void{
- this._button.width = stage.stageWidth;
- this._button.height = stage.stageHeight;
- }
- private function registerCallbacks():void{
- ExternalInterface.addCallback("startupload", this.startUpload);
- ExternalInterface.addCallback("removefile", this.removeFile);
- ExternalInterface.addCallback("updatefile", this.updateFileProperties);
- }
- private function filesSelectedHandler(_arg1:Event):void{
- this.addSelectedValidFiles(FileReferenceList(_arg1.target));
- }
- private function uploadFile():void{
- var _local1:URLRequest = new URLRequest();
- var _local2:File = this.getProcessedFile();
- var _local3:URLVariables = new URLVariables();
- var _local4:FileReference = _local2.getFileReference();
- _local3.message = _local2.getDescription();
- _local3.password = _local2.getPassword();
- _local3.trafficurl = _local2.getTrafficExchange();
- _local3.toemail = _local2.getRecipientEmail();
- _local3.fromemail = _local2.getUploaderEmail();
- _local3.multiemail = _local2.getMultipleRecipients();
- _local3.user = this._userID;
- _local3.hotlink = _local2.getHotlink();
- _local1.url = ((((((_local2.getServer() + "upload_done.php?UPLOAD_IDENTIFIER=") + _local2.getID()) + "&user=") + this._userID) + "&s=") + _local2.getsize());
- _local1.data = _local3;
- _local1.method = URLRequestMethod.POST;
- this.enableFileEvents(_local4, true);
- this.startTimeOutTracker();
- _local4.upload(_local1);
- }
- private function enableFileEvents(_arg1:FileReference, _arg2:boolean):void{
- var _local3:function;
- if (_arg2){
- _local3 = _arg1.addEventListener;
- } else {
- _local3 = _arg1.removeEventListener;
- };
- _local3(Event.OPEN, this.handleFileUploadEvent);
- _local3(IOErrorEvent.IO_ERROR, this.handleFileUploadEvent);
- _local3(SecurityErrorEvent.SECURITY_ERROR, this.handleFileUploadEvent);
- _local3(HTTPStatusEvent.HTTP_STATUS, this.handleFileUploadEvent);
- _local3(ProgressEvent.PROGRESS, this.handleFileUploadEvent);
- _local3(Event.COMPLETE, this.handleFileUploadEvent);
- _local3(DataEvent.UPLOAD_COMPLETE_DATA, this.handleFileUploadEvent);
- }
- private function handleFileUploadEvent(_arg1:object):void{
- var _local3:string;
- var _local2:FileReference = FileReference(_arg1.currentTarget);
- switch (_arg1.type){
- case Event.OPEN:
- JsEventDispatcher.dispatchEvent(JsEventDispatcher.UPLOAD_START, {fileID:this.getProcessedFile().getID()});
- break;
- case IOErrorEvent.IO_ERROR:
- this.stopTimeOutTracker();
- this.enableFileEvents(_local2, false);
- this.verifyEarlyCompletion();
- break;
- case SecurityErrorEvent.SECURITY_ERROR:
- this.stopTimeOutTracker();
- this.enableFileEvents(_local2, false);
- this.errorFile();
- break;
- case HTTPStatusEvent.HTTP_STATUS:
- this.stopTimeOutTracker();
- this.enableFileEvents(_local2, false);
- this.errorFile();
- break;
- case ProgressEvent.PROGRESS:
- this._lastProgressTime = new date().gettime();
- _local3 = this.getProcessedFile().getID();
- JsEventDispatcher.dispatchEvent(JsEventDispatcher.UPLOAD_PROGRESS, {
- fileID:_local3,
- bytesloaded:_arg1.bytesloaded,
- bytestotal:_arg1.bytestotal
- });
- break;
- case Event.COMPLETE:
- this.stopTimeOutTracker();
- break;
- case DataEvent.UPLOAD_COMPLETE_DATA:
- this.stopTimeOutTracker();
- this.enableFileEvents(_local2, false);
- this.successFile(_arg1.data);
- break;
- case Event.CANCEL:
- };
- }
- private function addSelectedValidFiles(_arg1:FileReferenceList):void{
- var big:* = false;
- var fileRef:* = null;
- var file:* = null;
- var fileProps:* = null;
- var j:* = 0;
- var fileRefList:* = _arg1;
- var files:* = fileRefList.fileList;
- var newFiles:* = [];
- var i:* = 0;
- while (i < files.length) {
- fileRef = files[i];
- try {
- if (fileRef.size > 4294967296){
- big = true;
- } else {
- big = false;
- };
- } catch(e:IOError) {
- big = true;
- };
- if (!big){
- if (!this.isDuplicatedFile(fileRef)){
- file = new File(fileRef, this.getRandomServer());
- newFiles.push(file);
- this._allFiles.push(file);
- };
- };
- i = (i + 1);
- };
- if (newFiles.length > 0){
- fileProps = "";
- j = 0;
- while (j < newFiles.length) {
- fileProps = (fileProps + ((((File(newFiles[j]).getID() + ";") + encodeURIComponent(File(newFiles[j]).getName())) + ";") + File(newFiles[j]).getsize()));
- if (j < (newFiles.length - 1)){
- fileProps = (fileProps + "||");
- };
- j = (j + 1);
- };
- JsEventDispatcher.dispatchEvent(JsEventDispatcher.FILES_ADDED, {fileProps:fileProps});
- };
- }
- private function verifyEarlyCompletion():void{
- var _local1:URLLoader = new URLLoader();
- var _local2:URLRequest = new URLRequest();
- var _local3:URLVariables = new URLVariables();
- var _local4:File = this.getProcessedFile();
- _local3.name = _local4.getName();
- _local3.user = this._userID;
- _local3.message = _local4.getDescription();
- _local3.password = _local4.getPassword();
- _local3.trafficurl = _local4.getTrafficExchange();
- _local3.toemail = _local4.getRecipientEmail();
- _local3.fromemail = _local4.getUploaderEmail();
- _local3.multiemail = _local4.getMultipleRecipients();
- _local2.url = ((((_local4.getServer() + "uploadquick.php?UPLOAD_IDENTIFIER=") + _local4.getID()) + "&user=") + this._userID);
- _local2.method = URLRequestMethod.POST;
- _local2.data = _local3;
- _local1.addEventListener(Event.COMPLETE, this.verificationXMLSuccess);
- _local1.addEventListener(IOErrorEvent.IO_ERROR, this.verificationXMLError);
- _local1.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.verificationXMLError);
- _local1.load(_local2);
- }
- private function verificationXMLSuccess(_arg1:Event):void{
- URLLoader(_arg1.currentTarget).removeEventListener(Event.COMPLETE, this.verificationXMLSuccess);
- URLLoader(_arg1.currentTarget).removeEventListener(IOErrorEvent.IO_ERROR, this.verificationXMLError);
- URLLoader(_arg1.currentTarget).removeEventListener(SecurityErrorEvent.SECURITY_ERROR, this.verificationXMLError);
- var _local2:xml = xml(_arg1.target.data);
- if (_local2.children().length() > 0){
- if (((_local2.children()[0].hasOwnProperty("@url")) && (!((_local2.children()[0].@url == ""))))){
- this.terminateFile(_local2.children()[0].@url);
- } else {
- this.errorFile();
- };
- } else {
- this.errorFile();
- };
- }
- private function verificationXMLError(_arg1:Event):void{
- URLLoader(_arg1.currentTarget).removeEventListener(Event.COMPLETE, this.verificationXMLSuccess);
- URLLoader(_arg1.currentTarget).removeEventListener(IOErrorEvent.IO_ERROR, this.verificationXMLError);
- URLLoader(_arg1.currentTarget).removeEventListener(SecurityErrorEvent.SECURITY_ERROR, this.verificationXMLError);
- this.errorFile();
- }
- private function isDuplicatedFile(_arg1:FileReference):boolean{
- var _local3:File;
- var _local2:uint;
- while (_local2 < this._allFiles.length) {
- _local3 = this._allFiles[_local2];
- if ((((_local3.getName() == _arg1.name)) && ((_local3.getsize() == _arg1.size)))){
- return (true);
- };
- _local2++;
- };
- return (false);
- }
- private function startTimeOutTracker():void{
- if (!this._timeOutTimer.running){
- this._timeOutTimer.start();
- };
- }
- private function stopTimeOutTracker():void{
- if (this._timeOutTimer.running){
- this._timeOutTimer.reset();
- };
- }
- private function timeOutTick(_arg1:TimerEvent):void{
- var _local2:number = new date().gettime();
- if ((_local2 - this._lastProgressTime) > TIME_OUT_TIME){
- this.getProcessedFile().getFileReference().cancel();
- this.stopTimeOutTracker();
- this.verifyEarlyCompletion();
- };
- }
- private function errorFile():void{
- JsEventDispatcher.dispatchEvent(JsEventDispatcher.UPLOAD_ERROR, {fileID:this.getProcessedFile().getID()});
- this.uploadNextFile();
- }
- private function terminateFile(_arg1:string):void{
- JsEventDispatcher.dispatchEvent(JsEventDispatcher.UPLOAD_SUCCESS, {
- fileID:this.getProcessedFile().getID(),
- url:_arg1
- });
- this.uploadNextFile();
- }
- private function successFile(_arg1:string):void{
- var arr:* = null;
- var fileURL:* = null;
- var data:* = _arg1;
- try {
- arr = data.split(";");
- arr = arr[2].split("'");
- fileURL = string(arr[1]);
- if ((((fileURL == "undefined")) || ((fileURL == "")))){
- this.errorFile();
- return;
- };
- JsEventDispatcher.dispatchEvent(JsEventDispatcher.UPLOAD_SUCCESS, {
- fileID:this.getProcessedFile().getID(),
- url:fileURL
- });
- this.uploadNextFile();
- } catch(e:error) {
- errorFile();
- uploadNextFile();
- };
- }
- private function getProcessedFile():File{
- return (this._allFiles[this._processedFileIndex]);
- }
- private function uploadNextFile():void{
- if (this._processedFileIndex < (this._allFiles.length - 1)){
- this._processedFileIndex++;
- this.uploadFile();
- } else {
- this._status = STATUS_FINISHED;
- };
- }
- private function getRandomServer():string{
- var _local1:number = math.round((math.random() * (this._serverList.length - 1)));
- return (this._serverList[_local1]);
- }
- public function startUpload():void{
- if (this._allFiles.length > 0){
- this._status = STATUS_UPLOADING;
- this._processedFileIndex = 0;
- this.uploadFile();
- };
- }
- public function removeFile(_arg1:string):void{
- var _local2:uint;
- var _local3:boolean;
- var _local4:uint;
- if (this._status == STATUS_FILE_SELECT){
- _local2 = 0;
- while (_local2 < this._allFiles.length) {
- if (this._allFiles[_local2].getID() == _arg1){
- this._allFiles.splice(_local2, 1);
- break;
- };
- _local2++;
- };
- } else {
- if (this._status == STATUS_UPLOADING){
- _local3 = false;
- if (this.getProcessedFile().getID() == _arg1){
- this.stopTimeOutTracker();
- this.enableFileEvents(this.getProcessedFile().getFileReference(), false);
- this.getProcessedFile().getFileReference().cancel();
- _local3 = true;
- };
- _local4 = 0;
- while (_local4 < this._allFiles.length) {
- if (this._allFiles[_local4].getID() == _arg1){
- this._allFiles.splice(_local4, 1);
- if (_local3){
- this._processedFileIndex--;
- };
- break;
- };
- _local4++;
- };
- if (_local3){
- this.uploadNextFile();
- };
- };
- };
- }
- public function updateFileProperties(_arg1:string, _arg2:string, _arg3:string, _arg4:string, _arg5:string, _arg6:string, _arg7:string):void{
- var _local8:File;
- var _local9:uint;
- if (this._status == STATUS_FILE_SELECT){
- _local9 = 0;
- while (_local9 < this._allFiles.length) {
- if (this._allFiles[_local9].getID() == _arg1){
- _local8 = this._allFiles[_local9];
- break;
- };
- _local9++;
- };
- _local8.setDescription(_arg2);
- _local8.setUploaderEmail(_arg3);
- _local8.setRecipientEmail(_arg4);
- _local8.setPassword(_arg5);
- _local8.setHotlink(_arg6);
- _local8.setMultipleRecipients(_arg7);
- };
- }
- }
- }//package com.mega.fileuploader
- package com.mega.fileuploader {
- import flash.external.*;
- public class JsEventDispatcher {
- public static const FILES_ADDED:string = "filesAdded";
- public static const FILES_REMOVED:string = "filesRemoved";
- public static const UPLOAD_START:string = "uploadStart";
- public static const UPLOAD_PROGRESS:string = "uploadProgress";
- public static const UPLOAD_SUCCESS:string = "uploadSuccess";
- public static const UPLOAD_ERROR:string = "uploadError";
- public static const UPLOAD_CANCEL:string = "uploadCancel";
- public static function dispatchEvent(_arg1:string, _arg2:object):void{
- switch (_arg1){
- case UPLOAD_START:
- ExternalInterface.call("onUploadStart", _arg2.fileID);
- break;
- case UPLOAD_PROGRESS:
- ExternalInterface.call("onUploadProgress", _arg2.fileID, _arg2.bytesloaded, _arg2.bytestotal);
- break;
- case UPLOAD_SUCCESS:
- ExternalInterface.call("onUploadSuccess", _arg2.fileID, _arg2.url);
- break;
- case UPLOAD_ERROR:
- ExternalInterface.call("onUploadError", _arg2.fileID);
- break;
- case UPLOAD_CANCEL:
- break;
- case FILES_ADDED:
- ExternalInterface.call("onFileSelect", _arg2.fileProps);
- break;
- };
- }
- }
- }//package com.mega.fileuploader
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement