Detect mouse no movement and call an action

  • tommy5
  • Born
  • Born
  • tommy5
  • Posts: 1
  • Loc: Ireland

Post 3+ Months Ago

I want a script to detect if the mouse has not moved for say 30 seconds, and if this is the case to then go to scene 2;

Any ideas.
Thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • zhaojany
  • Student
  • Student
  • User avatar
  • Posts: 79

Post 3+ Months Ago

Code: [ Select ]
function toScene2() {
    _root.gotoAndPlay("Scene 2");
}
mousex = _root._xmouse;
mousey = _root._ymouse;
function detectMouse() {
    if (mousex == _root._xmouse and mousey == _root._ymouse) {
        toScene2();
        clearInterval(detectInterval);
    } else {
        mousex = _root._xmouse;
        mousey = _root._ymouse;
    }
}
detectInterval = setInterval(detectMouse, 1000);
  1. function toScene2() {
  2.     _root.gotoAndPlay("Scene 2");
  3. }
  4. mousex = _root._xmouse;
  5. mousey = _root._ymouse;
  6. function detectMouse() {
  7.     if (mousex == _root._xmouse and mousey == _root._ymouse) {
  8.         toScene2();
  9.         clearInterval(detectInterval);
  10.     } else {
  11.         mousex = _root._xmouse;
  12.         mousey = _root._ymouse;
  13.     }
  14. }
  15. detectInterval = setInterval(detectMouse, 1000);
  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

that looks good , here is a complicated 1 .
http://www.zainals.com/blog/2006/06/11/ ... een-saver/
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

So, we need a function to run after 30 seconds if the mouse doesn't move ?

How about setting up a function to run after 30 seconds, then attaching an interval reset to the onMouseMove event ?

Code: [ Select ]
var done:Function = function():Void {
    clearInterval(counter);
    _root.onMouseMove = null;
    _root.gotoAndPlay("Scene 2");
}
var counter:Number = setInterval(done, 30000);
_root.onMouseMove = function(){
    clearInterval(counter);
    counter = setInterval(done, 30000);
}
  1. var done:Function = function():Void {
  2.     clearInterval(counter);
  3.     _root.onMouseMove = null;
  4.     _root.gotoAndPlay("Scene 2");
  5. }
  6. var counter:Number = setInterval(done, 30000);
  7. _root.onMouseMove = function(){
  8.     clearInterval(counter);
  9.     counter = setInterval(done, 30000);
  10. }

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 18 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.