# Function issue

**URL:** <https://forum.kirupa.com/t/function-issue/326906>\
**Category:** Uncategorized\
**Created:** [January 20, 2012, 4:51pm UTC](https://forum.kirupa.com/t/function-issue/326906 "2012-01-20T16:51:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mantis2010](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@mantis2010](https://forum.kirupa.com/u/mantis2010)\
**Post date:** [January 20, 2012, 4:51pm UTC](https://forum.kirupa.com/t/function-issue/326906/1 "2012-01-20T16:51:32Z")

</div>

[COLOR=#000000][FONT=verdana]I’m trying to run a function 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. [/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]here is my code:[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]standstill = 0;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]lastmove = 0;[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]timeout = 3000; [/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]this.onMouseUp = function(){[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]lastmove = getTimer(); idle(timeout);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.onMouseMove = function(){[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]lastmove = getTimer(); idle(timeout);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]};[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]aListener = new Object();[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]aListener.onKeyUp = function () {[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]lastmove = getTimer(); idle(timeout);};[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]Key.addListener(aListener);[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]function idle(time){[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.onEnterFrame = function(){[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]standstill = getTimer()- lastmove; [/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]trace(standstill);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]DogSleep.gotoAndPlay(2);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]if(standstill \>= time){ [/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]trace(“dog is sleeping”);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]this.onEnterFrame = null; [/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]standstill = 0;[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]this.onMouseMove = function(){[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]DogSleep.gotoAndPlay(300);[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]  
[COLOR=#000000][FONT=verdana]}[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]how do I do this? [/FONT][/COLOR][COLOR=#000000][FONT=verdana]any help is appreciated. [/FONT][/COLOR][COLOR=#000000][FONT=verdana]Thanks![/FONT][/COLOR]
