working on an image uploader -> http://photojojo.com/imageEditor/uploader/uploader2.swf
couple problems.
- my listener.onProgress isnt getting called
- it works fine with smaller files, but when i try to upload a lot of bigger files - it behaves like its working as it should but then nothing gets put on the server. or sometimes after a little while some of the files end up there.
this is the actionscript
import flash.net.FileReferenceList;
import flash.net.FileReference;
var listener:Object = new Object();
_global.fileListX = 107;
_global.fileListY = browseButton._y;
_global.yCounter = browseButton._y;
// dont let uploadButton work at start...only enable once browse has been called
uploadButton.enabled = false;
// holds the list of files
_global.files = new Array();
listener.onSelect = function(fileRefList:FileReferenceList) {
uploadButton.enabled = true;
// clear all the old checks if we had just done an upload
for(i=0; i < _global.howManyChecksToClear; i++) {
removeMovieClip("done_"+i);
}
// fileRefList.fileList == what was just selected in the browse window
// concatenate that to our existing list of files
// because array files should hold all the files
_global.files = _global.files.concat(fileRefList.fileList);
// a file reference holds information about a file from the fileList (ex name, size?)
var item:FileReference;
//uploadButton._x = browseButton._x; // move the upload button onto the screen now that files have been selected
// clear the file list text box so we can reprint everything
fileList.text = "";
// go through the files
for (var i:Number = 0; i<_global.files.length; i++) {
// put file in item
item = _global.files*;
// print the name of that file
fileList.text += item.name+"
"; // print files on screen
// create a new delete button
var newDeleteButton = _root.attachMovie("deleteButton", "box_"+i, i);
newDeleteButton.id = i;
newDeleteButton._y = _global.fileListY + (i*22); // this started at the y pos of the browse button (to line things up)
newDeleteButton._x = _global.fileListX; // static
// DELETE FILE
// 1. clear the file display list
// 2. remove item from array
// 3. reprint list of files
// 4. get rid of its "x" delete button
newDeleteButton.onRelease = function() {
// clear our display list of files
fileList.text = "";
// take out this file from our array of files
_global.files.splice(this.id,1);
// reprint our list of files
for (var i = 0; i<_global.files.length; i++) {
item = _global.files*;
fileList.text += item.name+"
";
}
// get rid of the x
removeMovieClip("box_"+i);
};
}
};
listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
trace("onProgress: " + file.name + " with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
}
listener.onComplete = function(file:FileReference):Void {
trace("onComplete: "+file.name);
};
var fileRef:FileReferenceList = new FileReferenceList();
fileRef.addListener(listener);
browseButton.onRelease = function() {
upload.enabled = true;
fileRef.browse([{description:"Image files", extension:"*.jpg;*.gif;*.png"}]);
};
uploadButton.onRelease = function() {
// go through the array of files uploading each one
this.enabled = false;
for (var i:Number = 0; i<_global.files.length; i++) {
item = _global.files*;
trace(item.name);
item.upload("http://photojojo.com/imageEditor/uploader/upload.php");
var newDoneIcon = _root.attachMovie("doneIcon", "done_"+i, i);
newDoneIcon.id = i;
newDoneIcon._y = _global.fileListY + (i*22); // this started at the y pos of the browse button (to line things up)
newDoneIcon._x = _global.fileListX; // static
}
// before we clear the file list, get how long it is - this is how many checks we'll have to delete next time they click "browse"
_global.howManyChecksToClear = _global.files.length;
// now clear the list since we're all done uploading.
_global.files.splice(0);
};