AS3 Uploader Hell

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 449

Post 3+ Months Ago

lol so lets kick this off by saying I have my reasons for using flash for my uploader and a lot of it stems from consistency and, well :banghead: IE. I have used several types of uploders and flash seems to work the best for my needs and is consistent across browsers including android.

So the uploader I made has the ability to upload single and multiple files It is a derivative of my AS2 uploader. I decided to upgrade the code awhile back and all worked fine. But I never fully tested out the multiple upload feature :oops: :lol: so that's my bad. I didn't need to use multiple file uploads since I upgraded the code. several of my other projects did however and they work fine with the AS2 version, So I do have a plan B.

Issue(s) are currently it is not setting up the complete handler event.

Here is the setup
ACTIONSCRIPT Code: [ Select ]
// This function will trigger the uploader to upload only one file ---- This works perfectly
function upload_single(e:MouseEvent) {
   
   // Open browse pane
   file.browse(file_types_array);
   
   // Set the file listeners
   configure_listeners(file);
   
}
 
// This function will trigger the uploader to upload multiple files -- this dose not
function upload_multiple(e:MouseEvent) {
   
   // Open browse pane
   file_list.browse(file_types_array);
   
   // Set the file listeners
   configure_listeners(file_list);
 
}
 
// This function will set the listeners for the upload processes
function configure_listeners(dispatcher:IEventDispatcher):void {
   
   // Setup the listeners
   dispatcher.addEventListener(Event.CANCEL, cancelHandler);
   dispatcher.addEventListener(Event.COMPLETE, completeHandler);
   dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
   dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
   dispatcher.addEventListener(Event.OPEN, openHandler);
   dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
   dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
   dispatcher.addEventListener(Event.SELECT, selectHandler);
   dispatcher.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,uploadCompleteDataHandler);
   
}
 
  1. // This function will trigger the uploader to upload only one file ---- This works perfectly
  2. function upload_single(e:MouseEvent) {
  3.    
  4.    // Open browse pane
  5.    file.browse(file_types_array);
  6.    
  7.    // Set the file listeners
  8.    configure_listeners(file);
  9.    
  10. }
  11.  
  12. // This function will trigger the uploader to upload multiple files -- this dose not
  13. function upload_multiple(e:MouseEvent) {
  14.    
  15.    // Open browse pane
  16.    file_list.browse(file_types_array);
  17.    
  18.    // Set the file listeners
  19.    configure_listeners(file_list);
  20.  
  21. }
  22.  
  23. // This function will set the listeners for the upload processes
  24. function configure_listeners(dispatcher:IEventDispatcher):void {
  25.    
  26.    // Setup the listeners
  27.    dispatcher.addEventListener(Event.CANCEL, cancelHandler);
  28.    dispatcher.addEventListener(Event.COMPLETE, completeHandler);
  29.    dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
  30.    dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
  31.    dispatcher.addEventListener(Event.OPEN, openHandler);
  32.    dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
  33.    dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
  34.    dispatcher.addEventListener(Event.SELECT, selectHandler);
  35.    dispatcher.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,uploadCompleteDataHandler);
  36.    
  37. }
  38.  


I'm going to search a bit now that I've put this out here maybe I'll find my answer. If you have any questions or suggestions I have a quick reply time.

I'm a few lines of code short of ripping my uploaders guts out and redoing it.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 449

Post 3+ Months Ago

:beerchug: Ok so I got it figured out now. So the issue is fileRefrenceList do not have the events I need. So i need to setup them up when I actually do the upload.

Working now
ACTIONSCRIPT Code: [ Select ]
// This function will process the upload
function upload() {
   
   // See if we are at the end of the files
   if(files.length == 0) {
     
      // Send complete message
      ExternalInterface.call("upload_complete", uploader_id);
     
      // Kick out
      return false;
     
   }
 
   // Get the file
   var file:FileReference = FileReference(files[0]);
   
   // Upload the file
   file.upload(upload_url);
   
   // Check for multiple upload
   if(browse_multiple) {
     
      // Set to false
      browse_multiple = false;
     
      // Set the file listeners
      configure_listeners(file);
     
      // Set to true
      browse_multiple = true;
     
   }
   
}
 
// This function will trigger the uploader to upload only one file
function upload_single(e:MouseEvent) {
 
   // Open browse pane
   file.browse(file_types_array);
   
   // Set the file listeners
   configure_listeners(file);
   
}
 
// This function will trigger the uploader to upload multiple files
function upload_multiple(e:MouseEvent) {
   
   // Open browse pane
   file_list.browse(file_types_array);
   
   // Set the file listeners
   configure_listeners(file_list);
   
}
 
// This function will set the listeners for the upload processes
function configure_listeners(dispatcher:IEventDispatcher):void {
   
   // Check for multiple upload ... Yes I know that looks retarded!
   if(browse_multiple || !browse_multiple) {
     
      // Setup the listeners
      dispatcher.addEventListener(Event.CANCEL, cancelHandler);
      dispatcher.addEventListener(Event.SELECT, selectHandler);
     
   }
   
   if(!browse_multiple) {
     
      // Setup the listeners
      dispatcher.addEventListener(Event.CANCEL, cancelHandler);
      dispatcher.addEventListener(Event.COMPLETE, completeHandler);
      dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
      dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
      dispatcher.addEventListener(Event.OPEN, openHandler);
      dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
      dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
      dispatcher.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,uploadCompleteDataHandler);
   
   }
   
}
 
  1. // This function will process the upload
  2. function upload() {
  3.    
  4.    // See if we are at the end of the files
  5.    if(files.length == 0) {
  6.      
  7.       // Send complete message
  8.       ExternalInterface.call("upload_complete", uploader_id);
  9.      
  10.       // Kick out
  11.       return false;
  12.      
  13.    }
  14.  
  15.    // Get the file
  16.    var file:FileReference = FileReference(files[0]);
  17.    
  18.    // Upload the file
  19.    file.upload(upload_url);
  20.    
  21.    // Check for multiple upload
  22.    if(browse_multiple) {
  23.      
  24.       // Set to false
  25.       browse_multiple = false;
  26.      
  27.       // Set the file listeners
  28.       configure_listeners(file);
  29.      
  30.       // Set to true
  31.       browse_multiple = true;
  32.      
  33.    }
  34.    
  35. }
  36.  
  37. // This function will trigger the uploader to upload only one file
  38. function upload_single(e:MouseEvent) {
  39.  
  40.    // Open browse pane
  41.    file.browse(file_types_array);
  42.    
  43.    // Set the file listeners
  44.    configure_listeners(file);
  45.    
  46. }
  47.  
  48. // This function will trigger the uploader to upload multiple files
  49. function upload_multiple(e:MouseEvent) {
  50.    
  51.    // Open browse pane
  52.    file_list.browse(file_types_array);
  53.    
  54.    // Set the file listeners
  55.    configure_listeners(file_list);
  56.    
  57. }
  58.  
  59. // This function will set the listeners for the upload processes
  60. function configure_listeners(dispatcher:IEventDispatcher):void {
  61.    
  62.    // Check for multiple upload ... Yes I know that looks retarded!
  63.    if(browse_multiple || !browse_multiple) {
  64.      
  65.       // Setup the listeners
  66.       dispatcher.addEventListener(Event.CANCEL, cancelHandler);
  67.       dispatcher.addEventListener(Event.SELECT, selectHandler);
  68.      
  69.    }
  70.    
  71.    if(!browse_multiple) {
  72.      
  73.       // Setup the listeners
  74.       dispatcher.addEventListener(Event.CANCEL, cancelHandler);
  75.       dispatcher.addEventListener(Event.COMPLETE, completeHandler);
  76.       dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
  77.       dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
  78.       dispatcher.addEventListener(Event.OPEN, openHandler);
  79.       dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
  80.       dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
  81.       dispatcher.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,uploadCompleteDataHandler);
  82.    
  83.    }
  84.    
  85. }
  86.  

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 9 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.