2 Replies Latest reply on Apr 16, 2009 1:21 PM by shintashi

    Objects in slideshow out of sync?

    shintashi Level 1

      I noticed after a few repetitions the images that disappear on one side and reappear on the other start to get out of sync with each other, eventually overlapping. I'm figuring that has something to do with the minute timing differences between the lines of code being read, and was wondering if there is some way to get the images to stop losing their relative positions to one another?

       

       

       

      spd = 0;

       


      onEnterFrame = function(){
      spd = Math.floor((slider_mc._x - _xmouse) * 0.1);
      if(spd > 15){spd = 15;}
      if(spd < -15){spd = -15;}

       


      rad1._x -= spd; rad2._x -= spd; rad3._x -= spd; rad4._x -= spd;
      rad5._x -= spd; rad6._x -= spd; rad7._x -= spd; rad8._x -= spd;

       

      if(rad1._x < 0){rad1._x = 550;} if(rad2._x < 0){rad2._x = 550;}
      if(rad3._x < 0){rad3._x = 550;} if(rad4._x < 0){rad4._x = 550;}
      if(rad5._x < 0){rad5._x = 550;} if(rad6._x < 0){rad6._x = 550;}
      if(rad7._x < 0){rad7._x = 550;} if(rad8._x < 0){rad8._x = 550;}

       

      if(rad1._x > 550){rad1._x = 0;} if(rad2._x > 551){rad2._x = 0;}
      if(rad3._x > 550){rad3._x = 0;} if(rad4._x > 551){rad4._x = 0;}
      if(rad5._x > 550){rad5._x = 0;} if(rad6._x > 551){rad6._x = 0;}
      if(rad7._x > 550){rad7._x = 0;} if(rad8._x > 551){rad8._x = 0;}

       

      mX.text = Number(_xmouse);
              mY.text = Number(_ymouse);
             
          dX.text = Number(slider_mc._x - _xmouse);
              dY.text = Number(slider_mc._y - _ymouse);
                 
      }

        • 1. Re: Objects in slideshow out of sync?
          kglad Adobe Community Professional & MVP

          there's no appreciable difference between the execution time of the lines in any one loop.

          there will be rounding differences because flash uses binary arithmetic and positions display items at the nearest .05 pixel.  to remedy, use variables to store the current position of your objects.  (and you could significantly simplify your coding and typing by using a for-loop for those movieclips.)

          • 2. Re: Objects in slideshow out of sync?
            shintashi Level 1

            I built a working for loop,

             

             

            onEnterFrame = function(){
            for (i=1;i<9;i++){

            spd = Math.floor((slider_mc._x - _xmouse) * 0.05);
            if(spd > 15){spd = 15;}
            if(spd < -15){spd = -15;}

             

            radical = this["rad"+i];   
            radical._x -= spd;
            if(radical._x < 0){radical._x = 550;}
            if(radical._x > 550){radical._x = 0;}

             

            }

             

            }

             

            -------

             

            but this  " to remedy, use variables to store the current position of your objects."

             

            How do you mean??

            like var integer:int = rad1._x;

            or var rad1._x:int = rad1._x;

            I'm not that familiar with declaration of integer/whole number variables.