9 Replies Latest reply: Dec 26, 2009 2:43 PM by kglad RSS

    On click detection

    d0brin Community Member

      Here is the thing i have flash game and what i want is when you click somewhare on your flash movie i want flash to detect the position and than to create movement for a designated movie clip from starter point to the selected with the mouse destination and than when it reaches the designated location i want the movie clip to play certain frame... is this possible? and if the second one is not pls tell me how to make the first part with the position detection and than making a movie clip to move form starter point to the detected position

        • 1. Re: On click detection
          kglad CommunityMVP

          you can use:

           

          import mx.transitions.Tween;

           

          this.onMouseDown = function() {
              t1 = new Tween(mc, "_x", mx.transitions.easing.Elastic.easeOut, mc._x, this._xmouse, 3, true);
              t2 = new Tween(mc, "_y", mx.transitions.easing.Elastic.easeOut, mc._y, this._ymouse, 3, true);
          };
          t1.onMotionFinished = function() {
              // use mc.swapDepths() is mc is not at a removeable depth
              mc.removeMovieClip();
          };

          • 2. Re: On click detection
            d0brin Community Member

            thanks for replaying but i kind of don't stand how to use the code can you help me by making me a sample .fla file or just guide me whare to put the code and stuff ? thanks a lot

            • 3. Re: On click detection
              kglad CommunityMVP

              that should be:

               

              import mx.transitions.Tween;

               

              this.onMouseDown = function() {
                  t1 = new Tween(mc, "_x", mx.transitions.easing.Elastic.easeOut, mc._x, this._xmouse, 3, true);
                  t2 = new Tween(mc, "_y", mx.transitions.easing.Elastic.easeOut, mc._y, this._ymouse, 3, true);
                  t1.onMotionFinished = function() {
                      // use mc.swapDepths() is mc is not at a removeable depth
                      mc.swapDepths(0);
                      mc.removeMovieClip();
                  };
              };

              • 4. Re: On click detection
                d0brin Community Member

                thanks so much it roks now i forgot to add this import mx.transitions.Tween; just one more thing can it be made not to shuffle until it stops on the targeted location? or...

                • 5. Re: On click detection
                  d0brin Community Member

                  oh and can you tell me how to edint this code:

                   

                  onClipEvent(mouseMove) {
                       var radians:Number = new Number(Math.atan2(
                          _root._ymouse-this._y,_root._xmouse-this._x)
                          );
                       var degrees:Number = new Number(
                          Math.round((radians*180/Math.PI)));
                          this._rotation = degrees+360;
                          updateAfterEvent();
                  }

                   

                  to work not for the mouse cursor but for a designated movie clip from the main stage? this is to make the movie clip that i made to move on click to point at designated MC

                  • 6. Re: On click detection
                    kglad CommunityMVP

                    change the easing to none:

                     

                    t1 = new Tween(mc, "_x", mx.transitions.easing.None.easeNone, mc._x, this._xmouse, 3, true);

                    t2 = new Tween(mc, "_y", mx.transitions.easing.None.easeNone, mc._y, this._ymouse, 3, true);

                     

                    p.s.  if you're still able, mark this thread as answered.

                    • 7. Re: On click detection
                      d0brin Community Member

                      10x

                      • 8. Re: On click detection
                        d0brin Community Member

                        ah and one more thing how to make this position to reastarts when it ends...?

                        • 9. Re: On click detection
                          kglad CommunityMVP

                          how do you make the mouse position do what?