5 Replies Latest reply on Jul 14, 2011 9:33 PM by kglad

    for (i=0; i<mgBW.length; i++) {

    Ron Colmen Level 2

      I'm trying to loop this but won't work. Could someone help me to get this fixed?

       

      var mgB:Array = [browseMC1, browseMC2, browseMC3];

      var mgBW:Array = [targetMC1, targetMC2, targetMC3];

      var mgPW:Array = [logoPreviewMC1, logoPreviewMC2, logoPreviewMC3];

       

      for (i=0; i<mgBW.length; i++) {

          mgB[i].ivar=i;

      tl.mgB[i].onRelease = function() {

      var fileType:Array = [{description: "Image files", extension: "*.jpg;*.gif;*.png"}]

      fRef.browse(fileType);

      }

       

      tl.targetXMC3 = tl.mgBW[this.ivar]._x;

      tl.targetYMC3 = tl.mgBW[this.ivar]._y;

       

      var fileLimit:Number = 1000*1024;

      var previewMCL:MovieClipLoader = new MovieClipLoader();

      var previewLO:Object = {};

       

      var logoMCL:MovieClipLoader = new MovieClipLoader();

      var logoLO:Object = {};

       

      var logoA:Array = [gmb_mc.logoz_mc1,gmb_mc.logoz_mc2];

       

      previewLO.onLoadInit = function(targetMC:MovieClip){

      mgBW[this.ivar]._alpha = 100;

      mgBW[this.ivar].forceSmoothing = true;

      mgBW[this.ivar].cacheAsBitmap = true;

      var aspectRatio:Number = mgBW[this.ivar]._width/mgBW[this.ivar]._height;

       

      if(aspectRatio >= tl.mgPW[this.ivar]._width/tl.mgPW[this.ivar]._height){

      mgBW[this.ivar]._width = tl.mgPW[this.ivar]._width;

      mgBW[this.ivar]._height = mgBW[this.ivar]._width/aspectRatio;

      mgBW[this.ivar]._x = tl.mgPW[this.ivar]._x;

          mgBW[this.ivar]._y = tl.mgPW[this.ivar]._y + (tl.mgPW[this.ivar]._height - mgBW[this.ivar]._height)/2;

      } else {

      mgBW[this.ivar]._height = tl.mgPW[this.ivar]._height;

      mgBW[this.ivar]._width = aspectRatio*mgBW[this.ivar]._height;

      mgBW[this.ivar]._y = tl.mgPW[this.ivar]._y;

          mgBW[this.ivar]._x = tl.mgPW[this.ivar]._x + (tl.mgPW[this.ivar]._width - mgBW[this.ivar]._width)/2;

      }

      logoIndex = 0;

      replaceLOGOF();

      }

      previewMCL.addListener(previewLO);

       

      logoLO.onLoadInit = function(targetMC:MovieClip){

      logoIndex++;

      mgBW[this.ivar].forceSmoothing = true;

       

      mgBW[this.ivar].aspectRatio = mgBW[this.ivar]._width/mgBW[this.ivar]._height;

      if(mgBW[this.ivar].aspectRatio>=mgBW[this.ivar]._parent.logoMC._width/mgBW[this.ivar]._par ent.logoMC._height){

      mgBW[this.ivar]._width = mgBW[this.ivar]._parent.logoMC._width;

      mgBW[this.ivar]._height = mgBW[this.ivar]._width/mgBW[this.ivar].aspectRatio;

      } else {

      mgBW[this.ivar]._height = mgBW[this.ivar]._parent.logoMC._height;

      mgBW[this.ivar]._width = mgBW[this.ivar].aspectRatio*mgBW[this.ivar]._height;

      }

       

      mgBW[this.ivar]._x = -mgBW[this.ivar]._width/2;

      mgBW[this.ivar]._y = -mgBW[this.ivar]._height/2;

       

      mgBW[this.ivar]._alpha = 100;

      mgBW[this.ivar]._parent.logoMC._visible = false;

      if(logoIndex<logoA.length){

      replaceLOGOF();

      } else {

      }

      }

      logoMCL.addListener(logoLO);

       

      function replaceLOGOF(){

      logoA[logoIndex].mgBW[this.ivar]._alpha = 0;

      logoA[logoIndex].logoIndex = logoIndex;

      logoMCL.loadClip(logoFileS,logoA[logoIndex].mgBW[this.ivar]);

      }

       

      var fRef:FileReference = new FileReference();

      var fRefLO:Object = new Object();

       

      fRefLO.onSelect = function(file:FileReference):Void {

          for(k=1; k<mgB.length; k++){

      mgB[k].enabled = false;

      }

      file.upload("/php/upload.php");

      }

      fRefLO.onCancel = function(file:FileReference):Void {

      _root.upldbg_mc._visible = false;

      _root.bar._visible = false;

      _root.border._visible = false;

      }

      fRefLO.onOpen = function(file:FileReference):Void {

      _root.upldbg_mc._visible = true;

      _root.bar._visible = true;

      _root.border._visible = true;

      }

      fRefLO.onProgress = function(file:FileReference, bl:Number, bt:Number):Void {

      if(bl > fileLimit) {

              cancelUploadF(file);

          }

      }

       

      fRefLO.onComplete = function(file:FileReference):Void {

      logoFileS = "/logoImages/"+file.name;

      if(tl.mgBW[this.ivar]._width>0){

      tl.mgBW[this.ivar].swapDepths(dep);

      tl.mgBW[this.ivar].removeMovieClip();

      tl.createEmptyMovieClip(mgBW[this.ivar],dep++);

      tl.mgBW[this.ivar]._x = tl.targetXMC3;

      tl.mgBW[this.ivar]._y = tl.targetYMC3;

      }

      tl.mgBW[this.ivar]._alpha = 0;

      previewMCL.loadClip(logoFileS,tl.mgBW[this.ivar]);

      }

       

      var fileRef:FileReference = new FileReference();

      fRef.addListener(fRefLO);

       

      function cancelUploadF(file:FileReference){

      file.cancel();

      tl.mgBW[this.ivar]._alpha = 100;

      if(!tl.mgBW[this.ivar].tf){

          tl.mgBW[this.ivar].createTextField("tf",dep++,0,0,tl.mgPW[this.ivar]._width,tl.mgPW[this. ivar]._height);

          with(tl.mgBW[this.ivar].tf){

          multiline = true;

          wordWrap = true;

          text = "Upload Excedes 1000kb Size Limit";

          }

          clearTimeout(removeTO);

          removeTO = setTimeout(removeTF,4000);

      }

      }

      function removeTF(){

      tl.mgBW[this.ivar].tf.removeTextField();

      }

      }

      };

        • 1. Re: for (i=0; i<mgBW.length; i++) {
          kglad Adobe Community Professional & MVP

          i don't see where it makes any difference which mgB element you click.  they'll all result in the same action (a file browse window opens).

           

          what is it that you want to occur?

          1 person found this helpful
          • 2. Re: for (i=0; i<mgBW.length; i++) {
            Ron Colmen Level 2

            In my webpage there are these 3 browse buttons (mgB). The user is allowed to upload 3 images and each uploaded image will show a preview in mgBW.

             

            or

             

            How can I enable the user to just use browseMC1 button to upload more than one image and make each uploaded image preview to display in targetMC1, targetMC2, etc.. in a sequence? to do this I've got the following code working but I'm not knowing how to make the image preview load in a sequence? (The first uploaded logo preview to be displayed in targetMC1 then the second uploaded image preview to be in targetMC2, etc...)

             

            var tl:MovieClip = this;

            var dep:Number = 0;

            var logoFileS:String;

            var logoIndex:Number;

             

            tl.targetMC1X = tl.targetMC1._x;

            tl.targetMC1Y = tl.targetMC1._y;

            var fileLimit:Number = 1000*1024;

             

            var previewMCL:MovieClipLoader = new MovieClipLoader();

            var previewLO:Object = {};

            var logoMCL:MovieClipLoader = new MovieClipLoader();

            var logoLO:Object = {};

            var logoA:Array = [gmb_mc.logoz_mc1,gmb_mc.logoz_mc2,gmb_mc.logoz_mc3];

             

            tl.browseMC1.onRelease = function() {

            var fileType:Array = [{description: "Image files", extension: "*.jpg;*.gif;*.png"}]

            fRef.browse(fileType);

            };

             

            previewLO.onLoadInit = function(targetMC1:MovieClip){

            targetMC1._alpha = 100;

            targetMC1.forceSmoothing = true;

            targetMC1.cacheAsBitmap = true;

            var aspectRatio:Number = targetMC1._width/targetMC1._height;

             

            if(aspectRatio >= tl.logoPreviewMC1._width/tl.logoPreviewMC1._height){

            targetMC1._width = tl.logoPreviewMC1._width;

            targetMC1._height = targetMC1._width/aspectRatio;

            targetMC1._x = tl.logoPreviewMC1._x;

                targetMC1._y = tl.logoPreviewMC1._y + (tl.logoPreviewMC1._height - targetMC1._height)/2;

            } else {

            targetMC1._height = tl.logoPreviewMC1._height;

            targetMC1._width = aspectRatio*targetMC1._height;

            targetMC1._y = tl.logoPreviewMC1._y;

                targetMC1._x = tl.logoPreviewMC1._x + (tl.logoPreviewMC1._width - targetMC1._width)/2;

            }

            logoIndex = 0;

            replaceLOGOF();

            }

            previewMCL.addListener(previewLO);

             

            logoLO.onLoadInit = function(targetMC1:MovieClip){

            logoIndex++;

            targetMC1.forceSmoothing = true;

            targetMC1.aspectRatio = targetMC1._width/targetMC1._height;

            if(targetMC1.aspectRatio>=targetMC1._parent.logoMC._width/targetMC1._parent.logoMC._height ){

            targetMC1._width = targetMC1._parent.logoMC._width;

            targetMC1._height = targetMC1._width/targetMC1.aspectRatio;

            } else {

            targetMC1._height = targetMC1._parent.logoMC._height;

            targetMC1._width = targetMC1.aspectRatio*targetMC1._height;

            }

             

            targetMC1._x = -targetMC1._width/2;

            targetMC1._y = -targetMC1._height/2;

             

            targetMC1._alpha = 100;

            targetMC1._parent.logoMC._visible = false;

            if(logoIndex<logoA.length){

            replaceLOGOF();

            }

            }

            logoMCL.addListener(logoLO);

             

            function replaceLOGOF(){

            logoA[logoIndex].targetMC1._alpha = 0;

            logoA[logoIndex].logoIndex = logoIndex;

            logoMCL.loadClip(logoFileS,logoA[logoIndex].targetMC1);

            }

             

            var fRef:FileReference = new FileReference();

            var fRefLO:Object = new Object();

             

            fRefLO.onSelect = function(file:FileReference):Void {

                file.upload("php/upload.php");

            }

            fRefLO.onCancel = function(file:FileReference):Void {

            _root.upldbg_mc._visible = false;

            }

            fRefLO.onOpen = function(file:FileReference):Void {

            _root.upldbg_mc._visible = true;

            }

            fRefLO.onProgress = function(file:FileReference, bl:Number, bt:Number):Void {

            if(bl > fileLimit) {

                    cancelUploadF(file);

                }

            }

             

            fRefLO.onComplete = function(file:FileReference):Void {

            logoFileS = "logoImages/"+file.name;

            if(tl.targetMC1._width>0){

            tl.targetMC1.swapDepths(dep);

            tl.targetMC1.removeMovieClip();

            tl.createEmptyMovieClip("targetMC1",dep++);

            tl.targetMC1._x = tl.targetMC1X;

            tl.targetMC1._y = tl.targetMC1Y;

            }

            tl.targetMC1._alpha = 0;

            previewMCL.loadClip(logoFileS,tl.targetMC1);

            }

             

            var fileRef:FileReference = new FileReference();

            fRef.addListener(fRefLO);

             

            function cancelUploadF(file:FileReference){

            file.cancel();

            tl.targetMC1._alpha = 100;

            if(!tl.targetMC1.tf){

                tl.targetMC1.createTextField("tf",dep++,0,0,tl.logoPreviewMC1._width,tl.logoPreviewMC1._h eight);

                with(tl.targetMC1.tf){

                multiline = true;

                text = "Upload Excedes 1000kb Size Limit";

                }

                clearTimeout(removeTO);

                removeTO = setTimeout(removeTF,4000);

            }

            }

            function removeTF(){

            tl.targetMC1.tf.removeTextField();

            }

            • 3. Re: for (i=0; i<mgBW.length; i++) {
              kglad Adobe Community Professional & MVP

              you can use the filereferencelist class if you want to allow multiple files to be selected by the user.

               

              to load the user's images into your swf, use something like:

               

              var targetNum:Number=1;

               

              fRefLO.onComplete = function(file:FileReference):Void {

              logoFileS = "logoImages/"+file.name;

              var target:MovieClip=tl.createEmptyMovieClip("targetMC"+targetNum++,dep++);

               

              tl.target._x = tl.targetMC1X;

              tl.target._y = tl.targetMC1Y;

              }

              tl.target._alpha = 0;

              previewMCL.loadClip(logoFileS,tl.target);

              }

              • 4. Re: for (i=0; i<mgBW.length; i++) {
                Ron Colmen Level 2

                Thanks Kglad. 

                • 5. Re: for (i=0; i<mgBW.length; i++) {
                  kglad Adobe Community Professional & MVP

                  you're welcome.