A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [F8] Moving an MC in the opposite direction of mouse move

  1. #1
    Junior Member
    Join Date
    Oct 2006
    Location
    Flintshire, N. Wales
    Posts
    24

    [F8] Moving an MC in the opposite direction of mouse move

    Hi,

    Does anybody know how to make a Movie Clip go in the opposite direction that the mouse goes in on a ratio? (e.g. when you move your mouse right the movie Clip slightly left)
    Here is a pretty good example of what I am looking for.

    I've tried
    code:

    Xcenter = 275;
    Ycenter = 200;

    _root.onEnterFrame = function(){
    _root.bg_mc._x = Xcenter - _root.xmouse;
    _root.bg_mc._y = Ycenter - _root.ymouse;
    }


    But it did'nt work at all, could somebody please help me?
    I'd be grateful for any help

  2. #2
    Senior Member
    Join Date
    Jan 2001
    Posts
    1,017
    Xcenter = 275;
    Ycenter = 200;

    _root.onEnterFrame = function(){
    _root.bg_mc._x = Xcenter - _xmouse;
    _root.bg_mc._y = Ycenter - _ymouse;
    }

    you simply did not use the correct mouse function
    mey the swartz be with you

    http://www.amirlotan.com

  3. #3
    Junior Member
    Join Date
    Oct 2006
    Location
    Flintshire, N. Wales
    Posts
    24
    Quote Originally Posted by alotan
    Xcenter = 275;
    Ycenter = 200;

    _root.onEnterFrame = function(){
    _root.bg_mc._x = Xcenter - _xmouse;
    _root.bg_mc._y = Ycenter - _ymouse;
    }

    you simply did not use the correct mouse function
    What do you mean? Do I have to use the onMouseMove function?

    --EDIT--

    It works now, thanks, but is there any way to stop it from going off the stage, here's the .fla file
    Last edited by lewys93; 11-02-2006 at 08:18 AM.

  4. #4
    Senior Member
    Join Date
    Jan 2001
    Posts
    1,017
    Quote Originally Posted by alotan
    you simply did not use the correct mouse function
    instead _root.xmouse use _xmouse
    mey the swartz be with you

    http://www.amirlotan.com

  5. #5
    Junior Member
    Join Date
    Oct 2006
    Location
    Flintshire, N. Wales
    Posts
    24
    thanks for your help but this has lead me to another problem, when I move the mouse to the right, you can see the background of the flash file

  6. #6
    Junior Member
    Join Date
    Oct 2006
    Location
    Flintshire, N. Wales
    Posts
    24
    Quote Originally Posted by lewys93
    thanks for your help but this has lead me to another problem, when I move the mouse to the right, you can see the background of the flash file
    I've fixed that now, but does anybody know how to get this to work on different layers? i.e Getting things closer up to move across faster, and things further away moving slower?

  7. #7
    Senior Member
    Join Date
    Jan 2001
    Posts
    1,017
    on(|EnterFrame){
    _root.closer_mc._x = Xcenter - _xmouse * 2 ;
    _root.closer_mc._y = Ycenter - _ymouse * 2;
    _root.far_mc._x = Xcenter - _xmouse ;
    _root.far_mc._y = Ycenter - _ymouse;
    }
    mey the swartz be with you

    http://www.amirlotan.com

  8. #8
    Junior Member
    Join Date
    Oct 2006
    Location
    Flintshire, N. Wales
    Posts
    24
    Thank you for your help, the final code I made is:
    code:

    Xcenter = 500;
    Ycenter = 300;
    _root.onMouseMove = function(){
    _root.bg_mc._x = Xcenter - _xmouse;
    _root.fg_mc._x = Xcenter - _xmouse *1.5;
    }


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