2
votes

is it possibile to set the position of the mouse cursor? This is what I would like to do: when the user presses the mouse button over a movieclip, the movieclip starts dragging and on enterframe the cursor is positioned in the middle of the movieclip (don't tell me about lockcenter because I can't use it this way since my movieclip registration point is set at its top left corner). Basically, I would like to be able to force the cursor to reach the center of the movieclip when the user clicks it. Is this possible?

4
Things like that would be a ruin for Adobe's Flash. Imagine you land on a website with evil Flash ads that wont let your mouse cursor move! In the end you can't create an ego shooter in Flash since you can't rotate your character infinitely in one direction (except there is a trick?). - Bitterblue

4 Answers

1
votes

I don't have proof, but I think that you are not allowed to take control of the cursor like that.

An alternative would be to hide the actual mouse cursor, and add a custom cursor instead that you could positioned relative to the real cursor position, or in the center of your drag target if that would be easier. The problem would be that you have no way of knowing the exact appearance of the user's cursor.

0
votes

In other words you're looking for this functionality: SetCursorPos.

You cannot control the cursor with Flash. You'll have to solve it otherwise - what about setting your movieclip's registration point to the center?!

0
votes

I don't think that's possible. The mouse coordinates are read only.

However I would suggest any of these instead :

  • Hide the mouse using Mouse.hide();.

  • Make your own pointer in the location of the mouse.

  • Control this pointer as per your wish.

or

  • When the mouse button is pressed, move the movieclip itself, if possible.
0
votes

Expanding on loxxy's response:

Instead of moving the mouse cursor to the center of the object with lockCenter, you can manually move the object to be centered about the mouse cursor when the MouseEvent.MOUSE_DOWN event is fired on the object (just before you call startDrag on the object)

Here's a simple example:

package  {
    import flash.display.Sprite;
    import flash.events.MouseEvent;

    public class Main extends Sprite{
        public function Main() {
            var drag_object:Sprite = new Sprite()
            drag_object.graphics.beginFill(0xFF0000, .5);
            drag_object.graphics.drawRect(0, 0, 50, 50);
            drag_object.graphics.endFill();

            drag_object.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
            drag_object.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);

            drag_object.x = 200;
            drag_object.y = 300;
            addChild(drag_object);
        }

        private function onMouseDown(e:MouseEvent):void {
            var obj:Sprite = e.target as Sprite;
            obj.x = e.stageX - (obj.width * .5);
            obj.y = e.stageY - (obj.height * .5);
            obj.startDrag();
        }

        private function onMouseUp(e:MouseEvent):void {
            var obj:Sprite = e.target as Sprite;
            obj.stopDrag();
        }

    }

}