Skip to main content
Known Participant
May 22, 2012
Question

OnClick...Goto Click Location

  • May 22, 2012
  • 1 reply
  • 816 views

i am new in actionscript.

actually i want to move a man to a location where user clicks.

but the problem is i don't know how to do this..

Can anyone help me??

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
May 22, 2012

You can use mouseX and mouseY to determine where the click is made and assign the character's x and y properties to those values.

Known Participant
May 22, 2012

import mx.transitions.Tween;

import mx.transitions.easing.*;

function moveToMouse(targetClip:MovieClip, timeSpan:Number) {

      this.onMouseDown = function() {

        var xM:Number = _root._xmouse;

        var yM:Number = _root._ymouse;

        var cX:Number = targetClip._x;

        var cY:Number = targetClip._y;

        var clickTweenX = new Tween(targetClip, "_x", Strong.easeOut, cX, xM, timeSpan, true);

        var clickTweenY = new Tween(targetClip, "_y", Strong.easeOut, cY, yM, timeSpan, true);

    };

}

moveToMouse(ManmovieClip, 5);

---------------------------------------------------------------------------------------------------------------------------------------

i tried above code..but still i am not getting success....

Ned Murphy
Legend
May 22, 2012

If you change your publish settings to AS2 it might work since that is AS2 code.  If you want to create an AS3 file, then you need to use AS3 code, which would include using the mouseX, mouseY, x and y properties, among other things.