VideoHive

Issue with a function

2 posts
  • Has been a member for 0-1 years
scarab2010 says

I’m trying to run a function, in AS2 , when after a specific amount of time of the mouse being idle a movieclip plays. Then when the mouse becomes active again a different movieclip plays. I have gotten my code work for the most part, but the last function runs over and over as the mouse is moving. I want it to run once, so the movieclip plays once.

here is my code:

standstill = 0; lastmove = 0; timeout = 3000;

this.onMouseUp = function(){ lastmove = getTimer(); idle(timeout); }; this.onMouseMove = function(){ lastmove = getTimer(); idle(timeout); };

aListener = new Object(); aListener.onKeyUp = function () { lastmove = getTimer(); idle(timeout);}; Key.addListener(aListener);

function idle(time){ this.onEnterFrame = function(){ standstill = getTimer()- lastmove; trace(standstill); DogSleep.gotoAndPlay(2); if(standstill >= time){ trace(“dog is sleeping”); this.onEnterFrame = null; standstill = 0;

this.onMouseMove = function(){ DogSleep.gotoAndPlay(300); } } } }

how do I do this? any help is appreciated. Thanks!

4 months ago
14 posts
  • Has been a member for 2-3 years
  • Sold between 1 000 and 5 000 dollars
  • United Kingdom
  • Referred between 1 and 9 users
tweeks says

you could set a timer that runs all the time (a ‘game loop’), and use Boolean vars to set when the mouse has been still or is moving? i’m not too hot with as2 but i could knock it up in as3 for you, let me know.

4 months ago
2964 posts
  • Has been a member for 2-3 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Beta Tester
  • Exclusive Author
  • Sold between 50 000 and 100 000 dollars
  • Elite Author
  • Bought between 10 and 49 items
  • Spain
  • Referred between 100 and 199 users
pezflash says

First of all, define properly the variables:

var standstill:Number = 0;

Last, delete the onEnterFrame function, do not set to null.

if(standstill >= time) {
trace(“dog is sleeping”);
delete this.onEnterFrame;
......
}
4 months ago
2 posts
  • Has been a member for 0-1 years
scarab2010 says

Hey Thanks! I was able to get this to work with the suggestions from both of you.

4 months ago
by
by
by
by
by