=== modified file 'sites/all/modules/swfupload/js/swfupload_widget.js'
--- js/swfupload_widget.js	2010-10-19 00:39:29 +0000
+++ js/swfupload_widget.js	2011-04-02 06:29:39 +0000
@@ -11,7 +11,7 @@ function SWFU(id, settings) {
   ref.instance = {};
   ref.upload_stack_length = 0;
   ref.max_queue_size = 0;
-  ref.upload_stack = {};
+  ref.upload_stack = [];
   ref.upload_stack_obj;
   ref.upload_button_obj;
   ref.upload_stack_size = 0;
@@ -131,12 +131,13 @@ function SWFU(id, settings) {
    * For all files in the stack, a file element will be added to the wrapper using ref.addFileItem().
    */
   ref.addStoredFiles = function() {
+    var fid = 0;
     for(var i in ref.upload_stack) {
       if (ref.upload_stack[i] == 0) {
         break;
       };
-      ref.upload_stack[i].id = i;
-      ref.upload_stack[i].fid = i;
+      fid = ref.upload_stack[i].fid;
+      ref.upload_stack[i].id = fid;
       ref.upload_stack[i].extension = ref.getExtension(ref.upload_stack[i].filename);
       ref.addFileItem(ref.upload_stack[i]);
 
@@ -724,31 +725,51 @@ function SWFU(id, settings) {
    * Updates the value of the hidden input field which stores all uploaded files
    */
   ref.updateStack = function(file) {
-    var fid, input_field, element;
-    var old_upload_stack = ref.upload_stack;
+    var fid, input_field, fobj, i;
+    var old_stack = {};
+    var filefid = 0;
     var total_size = 0;
-    ref.upload_stack = {};
 
+    // index array elements by fid
+    for (i in ref.upload_stack) {
+      fobj = ref.upload_stack[i];
+      fid = fobj.fid;
+      old_stack[fid] = fobj;
+    }
+    ref.upload_stack = [];
+    if (file) {
+      filefid = (file.fid ? file.fid : file.id);
+    }
+    i = 0;
+
+    // Loop through all 'processed' objects in the wrapper object.
+    // Keep data in the upload stack (possibly reordered) for all those objects,
+    // except for the object that corresponds to the 'file' function argument.
+    // (This implies that the wrapper object must already be updated to have
+    // the 'processed' class added/removed, before this function is called.)
     ref.wrapper_obj.find('.processed').each(function() {
       fid = $(this).attr('id');
 
-      // If no file is secified, the function is called after sorting
-      // There are no new values so the file object is not needed
-      // We only need to change the order of the stack 
-      if (!file) {
-        ref.upload_stack[fid] = old_upload_stack[fid];
+      if (fid !== filefid) {
+        // Do not change data for this file (only change order, possibly)
+        ref.upload_stack[i] = old_stack[fid];
+        total_size += parseInt(old_stack[fid]['filesize']);
       }
       else {
-        ref.upload_stack[fid] = {filename:file.filename || file.name, fid:fid};
+        // Add this file to the data (or update its data)
+        // (Note: file.size = int?)
+        ref.upload_stack[i] = {fid:fid, filename:file.filename || file.name, filesize:file.size};
         total_size += parseInt(file.size);
         for (var name in ref.instance.elements) {
           input_field = $('#edit-' + name + '_' + fid);
           if (input_field.size() !== 0) {
-            ref.upload_stack[fid][name] = (input_field.attr('type') == 'checkbox') ? input_field.attr('checked') : input_field.val();
+            ref.upload_stack[i][name] = (input_field.attr('type') == 'checkbox') ? input_field.attr('checked') : input_field.val();
           };
         };
       };
+      i++;
     });
+
     ref.upload_stack_size = total_size;
     ref.upload_stack_length = ref.objectLength(ref.upload_stack);
     ref.upload_stack_obj.val(ref.toJson(ref.upload_stack));
@@ -816,7 +837,8 @@ function SWFU(id, settings) {
             ref.swfu.setStats(stats);
 
             if (file_tr) {
-              // Update the hidden input field
+              // Update the hidden input field.
+              // (Note: passing file arg doesn't currently do anything)
               ref.updateStack(file);
             };
           };
@@ -850,10 +872,18 @@ function SWFU(id, settings) {
         return '"'+ v.replace(/\n/g, '\\n') +'"';
       case 'object':
         var output = '';
-        for(i in v) {
-          output += (output ? ',' : '') + '"' + i + '":' + ref.toJson(v[i]);
+        if (Object.prototype.toString.call(v) === '[object Array]') {
+          for(i in v) {
+            output += (output ? ',' : '') + ref.toJson(v[i]);
+          }
+          return '[' + output + ']';
+        }
+        else {
+          for(i in v) {
+            output += (output ? ',' : '') + '"' + i + '":' + ref.toJson(v[i]);
+          }
+          return '{' + output + '}';
         }
-        return '{' + output + '}';
       default:
         return 'null';
     };

=== modified file 'sites/all/modules/swfupload/swfupload.module'
--- swfupload.module	2011-02-04 00:33:35 +0000
+++ swfupload.module	2011-04-01 02:30:45 +0000
@@ -162,6 +162,15 @@ function swfupload_add_js($element) {
         $flash_url = base_path() . str_replace('.js', '.swf', array_shift($swfupload_library->scripts['2.2.0.1']));
       }
 
+      $files = array();
+      if (!empty($element['#value'])) {
+        // We need to create an array in JSON notation, not an object (because
+        // Chrome/Opera may lose ordering of the elements in an object).
+        // Therefore create an array with numeric 0-based keys.
+        foreach ($element['#value'] as $file) {
+          $files[] = $file;
+        }
+      }
       $settings['swfupload_settings'][$element['#id']] = array(
         'module_path' => $path,
         'flash_url' => $flash_url,
@@ -181,7 +190,7 @@ function swfupload_add_js($element) {
         'file_types_description' => ($element['#description'] ? $element['#description'] : ''),
         'file_upload_limit' => $limit,
         'custom_settings' => array(
-          'upload_stack_value' => (!empty($element['#value'])) ? swfupload_to_js($element['#value']) : '[]',
+          'upload_stack_value' => (!empty($files)) ? swfupload_to_js($files) : '[]',
           'max_queue_size' => ($field['widget']['max_filesize_per_node'] ? $field['widget']['max_filesize_per_node'] : 0),
         ),
       );

