3 Replies Latest reply on Dec 27, 2009 9:10 AM by kglad

    Make MC look at a targeted location

    d0brin Level 1

      So far from a previous post i created a MC that goes to a targeted location with this AS:

       

      import mx.transitions.Tween;

       

      this.onMouseDown = function() {
          t1 = new Tween(mc, "_x", mx.transitions.easing.None.easeNone,
                         mc._x, this._xmouse, 1, true);
          t2 = new Tween(mc, "_y", mx.transitions.easing.None.easeNone,
                         mc._y, this._ymouse, 1, true);
          t1.onMotionFinished = function() {
              // use mc.swapDepths() is mc is not at a removeable depth
              mc.swapDepths(0);
              _root.mc.gotoAndPlay("destroy");
          };
      };

       

      how to make it also to look at this location, not to stay static?

        • 1. Re: Make MC look at a targeted location
          kglad Adobe Community Professional & MVP

          tween the movieclip's _rotation property.

          • 2. Re: Make MC look at a targeted location
            d0brin Level 1

            yes but how can you write me thx a lot

            • 3. Re: Make MC look at a targeted location
              kglad Adobe Community Professional & MVP

               

              import mx.transitions.Tween;

               

              this.onMouseDown = function() {
                  t1 = new Tween(mc, "_x", mx.transitions.easing.None.easeNone,
                                 mc._x, this._xmouse, 1, true);
                  t2 = new Tween(mc, "_y", mx.transitions.easing.None.easeNone,
                                 mc._y, this._ymouse, 1, true);

              // you'll need to define c, a constant, that depends on your ref point

              t3 = new Tween(mc, "_rotation", mx.transitions.easing.None.easeNone, mc._rotation,c+180*Math.atan2(mc._y-_ymouse,mc._x-_xmouse)/Math.PI, 1, true);


                  t1.onMotionFinished = function() {
                      // use mc.swapDepths() is mc is not at a removeable depth
                      mc.swapDepths(0);
                      _root.mc.gotoAndPlay("destroy");
                  };
              };

               

              how to make it also to look at this location, not to stay static?