A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [AS2] Point and Click Movement

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    3

    [AS2] Point and Click Movement

    Okay, so I'm completely new to flash and I'm having a bit of trouble getting around the learning curve. What I'm trying to do right now is script my game so that the player has to press the 'M' key, then select a position on the screen to move to. Well, teleport rather-- the player won't be moving the piece as much as he will be placing it.

    So...how do I go about doing this?

    Thanks in advance!

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    So which part of this are you having trouble with? Detecting when player presses M key? Placing object on the screen at coordinates of mouse cursor?

  3. #3
    Junior Member
    Join Date
    Jun 2009
    Posts
    3
    Both, but the 'M' part is fairly simple, right? Its just a variable set?

    So, I have a clue as to how to set the M, but I have no idea as to the mouse cursor bit. =\

  4. #4
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    To place movie clip where mouse is clicked, first put instance of movie clip on the stage. Give it instance name "mymc". Now select the keyframe (not movie clip instance but the frame) and write code there:
    PHP Code:
    var mouseListener:Object = new Object();
    mouseListener.onMouseDown = function() {
        
    mymc._x _xmouse;
        
    mymc._y _ymouse;
    };
    Mouse.addListener(mouseListener); 

  5. #5
    Junior Member
    Join Date
    Jun 2009
    Posts
    3
    Ah, excellent! Thank you! Now, do I put that inside the function of onClipEvent (keypress 'M') or something completely different?

  6. #6
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    No, that was suppose to be separate from clipEvents and my example code does not require M to be pressed. If you have clipEvent to detect M key and you want to add this code there too, you probably need to rewrite it to something like this:

    this._x = _root._xmouse;
    this._y = _root._ymouse;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center