A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Follow Mouse (only in certain area)?

  1. #1
    Junior Member
    Join Date
    May 2007
    Posts
    23

    Follow Mouse (only in certain area)?

    I found several tutorials that work great for having movie objects follow the mouse but I haven't been able to find one that restricts it to only a certain area.

    This is one of the tutorials that I was looking at:
    http://www.spoono.com/flash/tutorial...rial.php?id=24

    What I basically want to do is have this hanging lamp tilt either left or right depending or where the mouse comes from. Hope it makes sense! Thanks in advance

    It's the red lamp on my website: www.buccianti.net

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    Here's a simple example which uses the one you linked to:
    PHP Code:
    // coordinates that define a rectangle
    var top:Number 0;
    var 
    bottom:Number 200;
    var 
    left:Number 0;
    var 
    right:Number 400;

    // mouse position
    var xMouse:Number;
    var 
    yMouse:Number;

    ball_mc.onEnterFrame = function()
    {
        
    // if the mouse is withing the rectangle
        
    if (_xmouse left && _xmouse right && _ymouse top && _ymouse bottom)
        {
            
    xMouse _xmouse;
            
    yMouse _ymouse;
        }
        
        
    // if the mouse coordinates exist
        
    if (xMouse != undefined && yMouse != undefined)
        {
            if(
    Math.abs(xMouse this._x) < 1) {
                
    this._x xMouse;
                
    this._y yMouse;
            } else {
                
    this._x -= (this._x-xMouse) / 6;
                
    this._y -= (this._y-yMouse) / 6;
            }
        }
    }; 

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