=== modified file 'sites/all/modules/swfupload/swfupload.module'
--- swfupload.module	2010-12-28 04:55:24 +0000
+++ swfupload.module	2011-02-04 00:09:41 +0000
@@ -135,54 +135,62 @@
  * Here we can safely attach our javascript
  */
 function swfupload_add_js($element) {
-  // Get the path to the swfupload module.
-  $path = drupal_get_path('module', 'swfupload');
-
-  $field = content_fields($element['#field_name'], $element['#type_name']);
-  $swfupload_library = jqp_library_load('swfupload');
-
-  if (drupal_add_library('swfupload', '2.2.0.1') !== FALSE) {
-    // Put the values of the list field and description field in the widget array
-    // so we can pass it to our hook_swfupload implementation.
-    $field['widget']['list_field'] = $field['list_field'];
-    $field['widget']['list_default'] = $field['list_default'];
-    $field['widget']['description_field'] = $field['description_field'];
-  
-    $limit = ($field['multiple'] == 1 ? 0 : ($field['multiple'] == 0 ? 1 : $field['multiple']));
-
-    // We need to store the variable $flash_url statically while the 2nd time the script is loaded,
-    // $swfupload_library->scripts['2.2.0.1'] will be empty.
-    static $flash_url;
-    if (!$flash_url) {
-      $flash_url = base_path() . str_replace('.js', '.swf', array_shift($swfupload_library->scripts['2.2.0.1']));
+  static $added = array();
+  // Prevent JS setting from being added twice, thus messing data up. (This can
+  // happen on drupal_rebuild_form(). D6 has no internal logic to catch this.)
+  if (!isset($added[$element['#id']])) {
+
+    // Get the path to the swfupload module.
+    $path = drupal_get_path('module', 'swfupload');
+
+    $field = content_fields($element['#field_name'], $element['#type_name']);
+    $swfupload_library = jqp_library_load('swfupload');
+
+    if (drupal_add_library('swfupload', '2.2.0.1') !== FALSE) {
+      // Put the values of the list field and description field in the widget array
+      // so we can pass it to our hook_swfupload implementation.
+      $field['widget']['list_field'] = $field['list_field'];
+      $field['widget']['list_default'] = $field['list_default'];
+      $field['widget']['description_field'] = $field['description_field'];
+
+      $limit = ($field['multiple'] == 1 ? 0 : ($field['multiple'] == 0 ? 1 : $field['multiple']));
+
+      // We need to store the variable $flash_url statically while the 2nd time the script is loaded,
+      // $swfupload_library->scripts['2.2.0.1'] will be empty.
+      static $flash_url;
+      if (!$flash_url) {
+        $flash_url = base_path() . str_replace('.js', '.swf', array_shift($swfupload_library->scripts['2.2.0.1']));
+      }
+
+      $settings['swfupload_settings'][$element['#id']] = array(
+        'module_path' => $path,
+        'flash_url' => $flash_url,
+        'upload_url' => url('swfupload'),  // Relative to the SWF file
+        'upload_button_id' => $element['#id'],
+        'file_post_name' => $element['#name'],
+        'file_queue_limit' => $limit,
+        'post_params' => array(
+          'sid' => _post_key(),
+          'file_path' => file_directory_path() .'/'. $field['widget']['file_path'],
+          'op' => 'move_uploaded_file',
+          'instance' => swfupload_to_js(array('name' => $element['#field_name'])),
+          'widget' => swfupload_to_js($field['widget']),
+        ),
+        'file_size_limit' => ($field['widget']['max_filesize_per_file'] ? (parse_size($field['widget']['max_filesize_per_file']) / 1048576) .'MB' : 0),
+        'file_types' => (empty($field['widget']['file_extensions']) ? '' : '*.'. str_replace(" ", ";*.", $field['widget']['file_extensions'])),
+        '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']) : '[]',
+          'max_queue_size' => ($field['widget']['max_filesize_per_node'] ? $field['widget']['max_filesize_per_node'] : 0),
+        ),
+      );
+      drupal_add_js('misc/tabledrag.js', 'core');
+      drupal_add_js("$path/js/swfupload_widget.js");
+      drupal_add_js($settings, 'setting');
+      
+      $added[$element['#id']] = TRUE;
     }
-
-    $settings['swfupload_settings'][$element['#id']] = array(
-      'module_path' => $path,
-      'flash_url' => $flash_url,
-      'upload_url' => url('swfupload'),  // Relative to the SWF file
-      'upload_button_id' => $element['#id'],
-      'file_post_name' => $element['#name'],
-      'file_queue_limit' => $limit,
-      'post_params' => array(
-        'sid' => _post_key(),
-        'file_path' => file_directory_path() .'/'. $field['widget']['file_path'],
-        'op' => 'move_uploaded_file',
-        'instance' => swfupload_to_js(array('name' => $element['#field_name'])),
-        'widget' => swfupload_to_js($field['widget']),
-      ),
-      'file_size_limit' => ($field['widget']['max_filesize_per_file'] ? (parse_size($field['widget']['max_filesize_per_file']) / 1048576) .'MB' : 0),
-      'file_types' => (empty($field['widget']['file_extensions']) ? '' : '*.'. str_replace(" ", ";*.", $field['widget']['file_extensions'])),
-      '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']) : '[]',
-        'max_queue_size' => ($field['widget']['max_filesize_per_node'] ? $field['widget']['max_filesize_per_node'] : 0),
-      ),
-    );
-    drupal_add_js('misc/tabledrag.js', 'core');
-    drupal_add_js("$path/js/swfupload_widget.js");
-    drupal_add_js($settings, 'setting');
   }
 
   return $element;

