7 Replies Latest reply on Dec 30, 2006 9:44 AM by kglad

    on roll over I have an mc follow the mouse, how do i send the mc back ...

    dtrace
      Basically, you roll over a piece of text, and it follows the mouse, using the following code.

      onClipEvent (load) {
      _x = this._x;
      _y = this._y;
      speed = 44;
      }
      onClipEvent (enterFrame) {
      if (_global.penthouseshit == 1) {
      endX = _root._xmouse;
      endY = _root._ymouse;
      _x += (endX-_x)/speed;
      _y += (endY-_y)/speed;
      }
      }


      However, the problem is that when I roll off this thing, it is sort of snapping back to it's original position. I'm thinking there is a way to animate it back to it's original state, but I'm not sure how to do this.

      Could you show me the way?

      Thanks.


        • 1. Re: on roll over I have an mc follow the mouse, how do i send the mc back ...
          kglad Adobe Community Professional & MVP
          change the first two lines of that onLoad statement to store your movieclip's initial _x and _y properties. (the first two lines currently do nothing.)

          and use an else branch of your if-statement to update that movieclip's _x,_y properties using those initial properties instead of endX and endY.
          • 2. Re: on roll over I have an mc follow the mouse, how do i send the mc back ...
            dtrace Level 1
            That makes sense and works...but the issue is now this other tween that you helped me with, that makes the MC hover.

            This is the code that makes them hover.

            I think it's the code that tells this hovering tween to 'start tween' that is causing the MC to jump.

            Here is the fla so you know what I'm talking about.

            http://www.devontracey.com/current3.fla

            thanks.



            import mx.transitions.Tween;
            function startTween(mc:MovieClip, range_num:Number, seconds:Number):Void {
            if (!mc.xMin) {
            mc.xMin = mc._x-range_num;
            mc.xMax = mc._x+range_num-7;
            mc.yMin = mc._y-range_num;
            mc.yMax = mc._y+range_num-14;
            }
            //adjust the easing class as needed
            mc.xNew = (Math.random()*(mc.xMax-mc.xMin))+mc.xMin;
            mc.yNew = (Math.random()*(mc.yMax-mc.yMin))+mc.yMin;
            mc.xTween = new Tween(mc, "_x", Regular.easeInOut, mc._x, mc.xNew, seconds, false);
            mc.yTween = new Tween(mc, "_y", Regular.easeInOut, mc._y, mc.yNew, seconds, false);
            mc.xTweenFinished = 0;
            mc.yTweenFinished = 0;
            mc.xTween.onMotionFinished = function() {
            mc.xTweenFinished = 1;
            if (mc.xTweenFinished & mc.yTweenFinished) {
            startTween(mc, range_num, seconds);
            }
            };
            mc.yTween.onMotionFinished = function() {
            mc.yTweenFinished = 1;
            if (mc.xTweenFinished & mc.yTweenFinished) {
            startTween(mc, range_num, seconds);
            }
            };
            }
            startTween(penthouse, 12, 72);
            startTween(midnight, 12, 82);
            startTween(photo, 12, 62);
            startTween(meeting, 12, 66);
            startTween(everything, 12, 80);
            startTween(space, 12, 77);
            penthousebutton.onRollOver = function() {
            penthouse.xTween.stop();
            penthouse.yTween.stop();
            };


            midnightbutton.onRollOver = function() {
            midnight.xTween.stop();
            midnight.yTween.stop();
            };
            midnightbutton.onRollOut = function() {
            midnight.xTween.resume();
            midnight.yTween.resume();
            };
            photobutton.onRollOver = function() {
            photo.xTween.stop();
            photo.yTween.stop();
            };
            photobutton.onRollOut = function() {
            photo.xTween.resume();
            photo.yTween.resume();
            };
            meetingbutton.onRollOver = function() {
            meeting.xTween.stop();
            meeting.yTween.stop();
            };
            meetingbutton.onRollOut = function() {
            meeting.xTween.resume();
            meeting.yTween.resume();
            };
            everythingbutton.onRollOver = function() {
            everything.xTween.stop();
            everything.yTween.stop();
            };
            everythingbutton.onRollOut = function() {
            everything.xTween.resume();
            everything.yTween.resume();
            };
            yourbutton.onRollOver = function() {
            space.xTween.stop();
            space.yTween.stop();
            };
            yourbutton.onRollOut = function() {
            space.xTween.resume();
            space.yTween.resume();
            };
            • 3. Re: on roll over I have an mc follow the mouse, how do i send the mc back ...
              kglad Adobe Community Professional & MVP
              you many not want to resume those tweens onRollOut then. if you want to start a new tween onRollOut (using the possibly new _x and _y properties of your buttons), then change the current rollOut handlers to do just that.
              • 4. Re: on roll over I have an mc follow the mouse, how do i send the mc back ...
                dtrace Level 1
                kglad,

                That seems to make sense, to start a new tween on roll out based on the current x and y position of the mc. That way, it wouldn't 'jump' but would instead go smoothly into the hovering.

                But, how would I start a new tween on roll out? The code would have to be the same as the previous 'hovering' function you made, right? But I would have to give it a new name?

                Then, if you roll over the mc again, wouldn't it only stop the first Tween instance?

                How would I make it stop the second one?

                Thanks

                • 5. Re: on roll over I have an mc follow the mouse, how do i send the mc back ...
                  kglad Adobe Community Professional & MVP
                  you'll delete the first tween onRollOut (or onRollOver) and start a new one. for example:

                  • 6. Re: on roll over I have an mc follow the mouse, how do i send the mc back ...
                    dtrace Level 1
                    kglad, amazing, it works. Thanks so much, you are a stud.

                    Do you have a personal site? I have tons of flash work and would like to know what you're up to, to perhaps call upon from time to time.


                    • 7. Re: on roll over I have an mc follow the mouse, how do i send the mc back ...
                      kglad Adobe Community Professional & MVP
                      www.gladstien.com

                      i'm a mathematician who changed careers to medicine. my day-job is pediatrics but i do a fair amount of med-expert work and lately, flash programming for a few clients that found me on this forum.