0 Replies Latest reply on May 20, 2006 2:33 AM by mr.morton

    Help with movie via actionscript

    mr.morton
      oki - so I am kinda new to flash. So very often I find pieces of actionscripts that other people made I can use... (like alot of other people i guess)

      I found this function that can move af movieclip from on point of another...


      _global.moveContent = function (targetMC, theFriction, theRatio, toScale, newXPos, newYPos, whenDone)
      {
      targetMC.onEnterFrame = null;
      var friction = theFriction;
      var ratio = theRatio;
      var speedY = 0;
      var speedX = 0;
      var speedScale = 1;
      var scaleDone = false;
      var XPosDone = false;
      var YPosDone = false;
      trace(targetMC._y); // OUTPUT _Y TO CHECK INCORRECT MOVEMENT
      targetMC.onEnterFrame = function ()
      {
      var _loc4 = newXPos - this._x;
      speedX = speedX * friction + (newXPos - this._x) * ratio;
      this._x = this._x + Math.round(speedX);
      var _loc3 = newYPos - this._y;
      speedY = speedY * friction + (newYPos - this._y) * ratio;
      this._y = this._y + Math.round(speedY);
      var _loc2 = toScale - this._xscale;
      speedScale = speedScale * friction + (toScale - this._xscale) * ratio;
      this._xscale = this._xscale + Math.round(speedScale);
      this._yscale = this._yscale + Math.round(speedScale);
      if (_loc3 == 0)
      {
      this._y = newYPos;
      YPosDone = true;
      } // end if
      if (_loc4 == 0)
      {
      this._x = newXPos;
      XPosDone = true;
      } // end if
      if (_loc2 == 0)
      {
      this._xscale = toScale;
      this._yscale = toScale;
      scaleDone = true;
      } // end if
      if (scaleDone && XPosDone && YPosDone)
      {
      whenDone();
      this.onEnterFrame = null;
      } // end if
      };
      };

      and it works excellent.... allmost... i am using it to move movieclips up and down (y coordinate) only, but when i set theRatio variabel low, like 0.2 it is not accurate, when I use it to move a moveclip 100px down and then 100px up after a couple of moves the movieclip will have changed position by about 1-3 px.

      I can't really figured out the math in the function, but maybe someone in here can tell me if it is possible to make it more accurate, so the shift will not accure?

      I use this to move the temp_mc:
      DOWN:
      _global.moveContent (temp_mc, 0,0.2, 100, temp_mc._x, temp_mc._y+100, null);
      and up:
      _global.moveContent (temp_mc, 0,0.2, 100, temp_mc._x, temp_mc._y+100, null);

      Maybe it is something with the Math.Round not to accurate or ??

      Any suggestions?

      Kind Regards
      Mr. Morton