5 Replies Latest reply on May 17, 2009 10:31 AM by kglad

    Filereference Upload - A script in this movie is causing Adobe Flash...

    GaryWalthrop

      This appears to be a sore topic these days. I have searched and found a large number of postings with this flash player message (A script in this move is causing Adobe Flash Player -n- to run slowly. If it continues...) But I haven't found a posting where it is resolved. I am trying to provide my client with an upload script. What I have so far works on small files but results in the aforementioned error message on large files. I saw a message a few days ago that talked about writing an onEnterFrame routine in a dummy movie clip that increments a counter, but there were no details about what that code might look like.  I have tried several iterations of that logic to no avail.  I know I am not the only one with this problem, and I do need to find a solution. I don't think that the server php settings are the problem.  Does anyone have any ideas?

       

      Thanks in advance,

      GW

       

       

       

      Action script from Layer 1: Frame 1 -

       

      _global.states = Array("AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY");
      _global.states.sort();
      _global.keepMemory = false;

       

      this.mc_uploadCtr.mc_stateError._visible = false;
      this.mc_uploadCtr._visible = false;
      this.mc_uploadCtr.enabled = false;

       

      // Get upload data
      var xmlData=new XML();
      xmlData.ignoreWhite=true;
      xmlData.onLoad = function(ok:Boolean) {
         if (ok) {
             processXmlData(this);       
         } else {
             dt_main.text = "XML did not load";
         }
      };

       

      function processXmlData(xml:XML) {
          _global.notifyToEmail    = xml.firstChild.childNodes[0].childNodes[0].nodeValue;
          _global.notifyFromEmail = xml.firstChild.childNodes[1].childNodes[0].nodeValue;
          _global.notifyFromName     = xml.firstChild.childNodes[2].childNodes[0].nodeValue;
      }

       

      System.useCodepage = true;
      xmlData.load('uploadData.xml');

       

      _global.keepInMemory = function(keep:Boolean) {
          if ((keep == true) and (_global.keepMemory == false)) {
              _global.keepMemory = true;
              this.createEmptyMovieClip("dummy_mc", 999);
              this.dummy_mc.onEnterFrame = function () {
                  while(_global.keepMemory == true) {
                      var count:Number = count + 1;
                  }
              }
          } else {
              if (_global.keepMemory = true) {
                  _global.keepMemory = false;
                  this.dummy_mc.unloadMovie();
              }
          }
      }

       

      stop();

       

       

       

       

      Action Script from upload movie clip:

       

      import flash.net.FileReference;
      var progressBar:MovieClip;
      var reference:FileReference = new FileReference();
      var referenceListener:Object = {};
      var scriptLocation:String = 'uploader.php';
      var progressBarHeight:Number = 10;
      var progressBarY:Number = 50;
      var progressBarColor:Number = 0x66ccff;

       

      reference.addListener(referenceListener);
      referenceListener.onSelect = activateUploadButton;
      referenceListener.onProgress = updateProgress;
      referenceListener.onComplete = checkIn;
      referenceListener.onHTTPError = handleError;
      referenceListener.onIOError = handleError;
      referenceListener.onSecurityError = handleError;

       

      btn_uploadFile._visible = false;
      btn_selectFile.onRelease = choose;
      btn_uploadFile.onRelease = uploadCurrent;

       

      function activateUploadButton():Void {
          display_txt.text = reference.name;
          btn_uploadFile._visible = true;
          btn_uploadFile.enabled = true;
      }

       

      function choose():Void {
          reference.browse([{description:'Images (*.ai, *.drw, *.jpg, *.jpeg, *.gif, *.pdf, *.png, *.psd, *.psp, *.tif,)', extension:'*.ai; *.drw; *.jpg; *.jpeg; *.gif; *.pdf; *.png; *.psd; *.psp; *.tif'}]);
      }

       

      function handleError(errorName:String, detail:Object):Void {
          restart();
          if (arguments.length === 2) {
              if (typeof detail === 'number') {
                  display_txt.text = 'HTTP Error #'+detail;
              } else {
                  display_txt.text = 'Security Error: '+detail;
              }
          } else {
              display_txt.text = 'IO Error';
          }
      }

       

      function makeProgressBar(x:Number, y:Number):MovieClip {
          var bar:MovieClip = createEmptyMovieClip('progressBar_mc', 0);
          bar._visible = false;
          bar.beginFill(progressBarColor);
          bar.lineTo(display_txt._width, 0);
          bar.lineTo(display_txt._width, progressBarHeight);
          bar.lineTo(0, progressBarHeight);
          bar.lineTo(0, 0);
          bar.endFill();
          bar._width = 0;
          bar._visible = true;
          bar._x = x;
          bar._y = y;
          return bar;
      }

       

      function restart():Void {
          removeMovieClip(progressBar);
          display_txt.text = '';
          btn_uploadFile._visible = false;
          btn_selectFile._visible = true;
      }

       

      function updateProgress(fileReference:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
          display_txt.text = fileReference.name+' - '+Math.ceil((bytesLoaded/bytesTotal)*100)+'%';
          progressBar._width = Math.ceil(display_txt._width*(bytesLoaded/bytesTotal));
      }

       

      function uploadCurrent():Void {
          btn_selectFile._visible = false;
          btn_uploadFile.enabled = false;
          progressBar = makeProgressBar(0, progressBarY);
          _global.keepInMemory(true);
          reference.upload(scriptLocation);
      }

       


      function checkIn():Void {
          _global.keepInMemory(false);
          moveFile();
          notify()
          restart();
      }

       

      function moveFile():Void {
            _global.uploadedFile = (_global.uploadFolder + '/' + reference.name);
      //    var lv_result:LoadVars = new LoadVars();
      //    var lv_move = new LoadVars();
      //    lv_move.fileName = reference.name;
      //    lv_move.rootFolder = (_global.rootFolder);
      //    lv_move.sourceFolder = (_global.uploadFolder);
      //    lv_move.targetFolder = (_global.uploadFolder);
      //    lv_move.sendAndLoad("mover.php", lv_result, "POST");
      }

       

      function notify():Void {
          var st_companyName:String = ('<tr><td>Company name:</td><td>'+_global.companyName+'</td></tr>')
          var st_contactName:String = ('<tr><td>Contact name:</td><td>'+_global.contactName+'</td></tr>')
          var st_phoneNumber:String = ('<tr><td>Phone number:</td><td>'+_global.phoneNumber+'</td></tr>')
          var st_address:String = "";
          if (_global.address2 <> "") {
              st_address = ('<tr><td>Address:</td><td>'+_global.address1+'</td></tr><tr><td> </td><td>'+_global.address2+'</td></tr><tr><td> </td><td>'+_global.addressCity+', '+_global.addressState + ' ' + _global.addressZip + '</td></tr>');
          } else {
              st_address = ('<tr><td>Address:</td><td>'+_global.address1+'</td></tr><tr><td> </td><td>'+_global.addressCity+', '+_global.addressState+' '+ _global.addressZip + '</td></tr>');
          }
          var st_email:String = ('<tr><td>E-Mail:</td><td>'+_global.email+'</td></tr>')
          var st_quantity:String = ('<tr><td>Quantity:</td><td>'+_global.quantity+'</td></tr>')
          var st_sides:String = ('<tr><td>Sides:</td><td>'+_global.sides+'</td></tr>')
          var st_paperWeight:String = ('<tr><td>Paper weight:</td><td>'+_global.sides+'</td></tr>')
          var st_jobDescription:String = ('<tr><td>Desc/Title of job:</td><td>'+_global.jobDescription+'</td></tr>')
          var st_uploadedFile:String = ('<tr><td>Uploaded file:</td><td>'+_global.uploadedFile+'</td></tr>')
         
          var result_lv:LoadVars = new LoadVars();
          result_lv.onLoad = function(success:Boolean) {
          if (success) {
          } else {
          }
          };   
          var lv_notify = new LoadVars();
          lv_notify.sender_fromEmail = _global.notifyFromEmail;
          lv_notify.sender_toEmail = _global.notifyToEmail;
          lv_notify.sender_fromName = _global.notifyFromName;
          lv_notify.sender_subject = ('File received from ' + _global.companyName);
          lv_notify.sender_message = ('<table width="550" border="1" align="left">' + st_companyName + st_contactName + st_phoneNumber + st_address + st_email + st_quantity + st_sides + st_paperWeight + st_jobDescription + st_uploadedFile + '</table>');
          lv_notify.sendAndLoad("sendmail.php", result_lv, "POST");
          return;
      }

       

      uploader.php -<?php
          if ($_FILES['Filedata']['name']) {
              upload_max_filesize = 100M;
              post_max_size = 100M;
              move_uploaded_file($_FILES['Filedata']['tmp_name'], 'uploads/' . basename($_FILES['Filedata']['name']));
          }
      ?>