1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
/*
Script Written By: Adam Khoury @ www.developphp.com
*/
// First thing is to set the flashing upload message clip to invisible
uploadMsg.visible = false;
// Set the URL for the PHP uploader script
var URLrequest:URLRequest = new URLRequest("uploader_script.php");
// Assign the image types Filter
var imageTypes:FileFilter = new FileFilter("Images (*.jpg, *.jpeg)", "*.jpg; *.jpeg;");
// Assign the document types filter
var allTypes:Array = new Array(imageTypes);
// Set the FileReference name
var fileRef:FileReference = new FileReference();
// Add event listeners for its various fileRef functions below
fileRef.addEventListener(Event.SELECT, syncVariables);
fileRef.addEventListener(Event.COMPLETE, completeHandler);
fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler);
// Add event listeners for your 2 buttons
browse_btn.addEventListener(MouseEvent.CLICK, browseBox);
upload_btn.addEventListener(MouseEvent.CLICK, uploadVars);
// Function that fires off when the user presses "browse for a file"
function browseBox(event:MouseEvent):void {
fileRef.browse(allTypes);
}
// Function that fires off when the user presses the "upload it now" btn
function uploadVars(event:MouseEvent):void {
uploadMsg.visible = true;
fileRef.upload(URLrequest);
upload_btn.visible = false;
}
// Function that fires off when File is selected from PC and Browse dialogue box closes
function syncVariables(event:Event):void {
fileDisplay_txt.text = "" + fileRef.name;
blocker.visible = false;
upload_btn.visible = true;
progressBar.width = 2;
var variables:URLVariables = new URLVariables();
variables.todayDate = new Date();
var keyStr:String;
var valueStr:String;
var paramObj:Object=LoaderInfo(this.root.loaderInfo).parameters;
for (keyStr in paramObj)
{
valueStr = String(paramObj[keyStr]);
var myText = valueStr;
}
variables.Name = myText; // This could be an input field variable like in my contact form tutorial : )
URLrequest.method = URLRequestMethod.POST;
URLrequest.data = variables;
}
// Function that fires off when upload is complete
function completeHandler(event:Event):void {
uploadMsg.visible = false;
blocker.visible = true;
status_txt.text = fileRef.name + " ha sido cargado.";
fileDisplay_txt.text = "";
}
// Function that fires off when the upload progress begins
function progressHandler(event:ProgressEvent):void {
// we want our progress bar to be 200 pixels wide when done growing so we use 200*
// Set any width using that number, and the bar will be limited to that when done growing
progressBar.width = Math.ceil(200*(event.bytesLoaded/event.bytesTotal));
} |
Partager