dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Detecting mouse movement

  1. #1
    Member
    Join Date
    Jul 2007
    Posts
    91

    Detecting mouse movement

    Example: If you do nothing with the mouse for about 3 seconds, hide the thumbnails. Otherwise, show a thumbnail.

    How to do something like this?

  2. #2
    Member
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    76
    You have to create a timer variable that will be reseted when the mouse moves. If the timer is bigger than the defined amount, the thumbnail will be hidden.

    Here's a quite example (I haven't tested it but it should work)
    Code:
    // Copy this into the "When movie starts" script.
    var timer:uint = 0;
    var lastMouseX:uint = 0;
    var lastMouseY:uint = 0;
    const timerLimit:uint = 60; // in frames
    
    // Copy this into the "On every frame" script
    if(mouseX != lastMouseX || mouseY != lastMouseY)
    	timer = 0;
    
    element("thumbnail").visible = !(timer >= timerLimit);
    
    lastMouseX = mouseX;
    lastMouseY = mouseY;
    timer++;
    Let me know whether it works or if you need further help (e.g. for a smooth fading effect etc.)

  3. #3
    Member
    Join Date
    Jul 2007
    Posts
    91
    Thank leifi. It works, but I wonder whether there will be better to use the command setInterval.

    ---

    Code:
    done = function() 
    {
    	clearInterval(counter);
    	element ("thumbnail")._visible = false;
    }
    counter = setInterval(done, 3000);
    _root.onMouseMove = function()
    {
    	clearInterval(counter);
    	counter = setInterval(done, 3000);
    	element ("thumbnail")._visible = true;
    }
    Quote Originally Posted by leifi View Post
    Let me know whether it works or if you need further help (e.g. for a smooth fading effect etc.)
    I still have a lot of questions but I will return to these questions another time. Thank you again for helping.
    Last edited by 3DH; 03-07-2010 at 11:21 PM.

  4. #4
    Member
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    76
    Of course you can do it this way... But then it's better to use the Timer class of flash. The official documentation says:
    Instead of using the setInterval() method, consider creating a Timer object, with the specified interval, using 0 as the repeatCount parameter (which sets the timer to repeat indefinitely).

    Source: http://livedocs.adobe.com/flash/9.0/...ml#setInterval

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