# Monitoring mouse movement to invoke a tween or not

**URL:** <https://forum.kirupa.com/t/monitoring-mouse-movement-to-invoke-a-tween-or-not/325104>\
**Category:** Uncategorized\
**Created:** [September 26, 2011, 7:30pm UTC](https://forum.kirupa.com/t/monitoring-mouse-movement-to-invoke-a-tween-or-not/325104 "2011-09-26T19:30:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeancnicolas](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@jeancnicolas](https://forum.kirupa.com/u/jeancnicolas)\
**Post date:** [September 26, 2011, 7:30pm UTC](https://forum.kirupa.com/t/monitoring-mouse-movement-to-invoke-a-tween-or-not/325104/1 "2011-09-26T19:30:21Z")

</div>

I want to have a movieclip have its alpha tween in, when I move the mouse, and fade out when I stop it. Alas - with either an onEnterFrame or onMouseMove if the mouse is moving - it keeps repeating the tween function - how do I make it fire the tween function only once…? here’s what Ive done - but its too unreliable …

```auto
var mousex:Number;var mousey:Number;
var moving:Boolean = false;
onEnterFrame = function()
{
	if(mousex == _xmouse && mousey == _ymouse) // the mouse isnt moving
	{
		if(moving == true) // was previous frame mouse moving?
	        {
		     bo.alphaTo(0,5);
	        }
	        moving = false;
	}
	else
	{
		moving = true; // the mouse is moving
		bo.alphaTo(100,2);
	}
	mousex = _xmouse; // store current mouse pos
	mousey = _ymouse;
}

```

any tips out there!?
