A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: MC follow mouse click

Threaded View

  1. #1
    Senior Member
    Join Date
    Jun 2007
    Location
    Nottingham, England
    Posts
    203

    MC follow mouse click

    So I'm trying to do something incredibly simple and It just isn't working properly. I'm annoyed at myself for not being able to find a solution but I need a fresh head on it!

    Imagine we have a MovieClip called "box". When I click somewhere on the screen, I want the box MC to move to that position. So I wrote something like this (just for horizontal movement):
    PHP Code:
    onMouseDown=function(){
    moveTo(_xmouse);
    };

    function 
    moveTo(newx){
    box.onEnterFrame=function(){
    if(
    box._x<newx){
    box._x+=5;
    }else if(
    box._x>newx){
    box._x-=5;
    }else{
    delete box.onEnterFrame;
    }
    };

    Now this works to a degree, except that when the box MC moves to the right position, it then proceeds to vibrate on the spot. I thought it was probably because it can never move to the exact position of _xmouse because I'm adding 10 to the x property which is why the condition is never met. However even if I just add 1 instead of 10, I still have the same problem..

    Any ideas before I go mad?
    Last edited by lightspeed10; 02-15-2010 at 06:36 PM.

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