2 Replies Latest reply on Jun 14, 2007 9:30 AM by ravenchaos

    HELP PLEASE....move movie clip using averages

    ravenchaos
      In flash, I am trying to get a movie clip/object to move to the average between two other objects. In other words, I have dot A (pa) and dot C (pc) and as I move them, I want dot B (pb) to be dead center of the two...can anyone help me figure out how to do this? Here is the script I have so far, and commented out on the bottom is the formula I need, but don't know how to get to work:

      pa.onPress = function() {
      this.startDrag(false,
      _root.groove_1_mc._x,
      _root.groove_1_mc._y - 382,
      _root.groove_1_mc._x,
      _root.groove_1_mc._y);

      };
      pa.onRelease = function() {
      stopDrag();
      };

      pc.onPress = function() {
      this.startDrag(false,
      _root.groove_2_mc._x,
      _root.groove_2_mc._y - 382,
      _root.groove_2_mc._x,
      _root.groove_2_mc._y);
      };
      pc.onRelease = function() {
      stopDrag();
      };

      var pax = pa._x;
      var pay = pa._y;
      var pcx = pc._x;
      var pcy = pc._y;
      var cax = pcx - pax;
      var cay = pcy - pay;


      this.createEmptyMovieClip("cnt", 1000);
      cnt.lineStyle(2, 0xFFFFFF, 100);
      cnt.moveTo(pa._x, pa._y);
      cnt.lineTo(pc._x, pc._y);
      cnt.lineTo(pa._x, pa._y);
      cnt.moveTo(pa._x, pa._y);

      //pb.y (green dot) needs to be equal to the y axis of pa (left red dot) plus the y axis of pc (right red dot) divided by 2
      //pb.y = (pa._y + pc._y)/2;
      //pb.x (green dot) needs to be equal to the x axis of pa (left red dot) plus the x axis of pc (right red dot) divided by 2
      //pb.x = (pa._x + pc._x)/2;
        • 1. Re: HELP PLEASE....move movie clip using averages
          Pop_Clingwrap Level 1
          put 3 clips on the stage called 'dota' 'dotb' and 'dotc' then put the following script in frame 1:

          dotc.onPress = dota.onPress = function()
          {
          this.startDrag();
          this.onMouseMove = function()
          {
          setDotB();
          }
          }

          dotc.onRelease = dota.onRelease = function()
          {
          this.stopDrag();
          }

          function setDotB()
          {
          var Xdif:Number = dotc._x - dota._x;
          dotb._x = dota._x + (Xdif / 2);
          }

          When you drag either dota or dotc, dotb will stay eevenly between them both.
          You may have to add some parameters to the startDrag() in order to lock the y position.

          Hope this helps
          • 2. Re: HELP PLEASE....move movie clip using averages
            ravenchaos Level 1
            Thanks ALL, I found the solution. I just forgot to put in a '_' so that my fromula read:

            pb._y = (pa._y + pc._y)/2
            pb._x = (pa._x + pc._x)/2

            instead of the previous (and wrong):

            pb.y = (pa._y + pc._y)/2
            pb.x = (pa._x + pc._x)/2