# Stop looping on a hittest

**URL:** <https://forum.kirupa.com/t/stop-looping-on-a-hittest/130769>\
**Category:** Uncategorized\
**Created:** [December 8, 2004, 12:44pm UTC](https://forum.kirupa.com/t/stop-looping-on-a-hittest/130769 "2004-12-08T12:44:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hat\_rack](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@hat\_rack](https://forum.kirupa.com/u/hat_rack)\
**Post date:** [December 8, 2004, 12:44pm UTC](https://forum.kirupa.com/t/stop-looping-on-a-hittest/130769/1 "2004-12-08T12:44:35Z")

</div>

I have a mc that slides in when the mouse is over it, using a hittest. heres the code:

```auto

onClipEvent (load) {
this._x = 670;
vel = 10
}
onClipEvent (enterFrame) {
	if(this.hitTest(_root._xmouse,_root._ymouse,true))
		_root.newy = 412;
	else 
		_root.newy = 630;

	fukx += (_root.newy-_x)/vel
	_x = Math.round(fukx);
}

```

the reason im not using rollOver is that there are other rollOvers within the mc and 2 in one mc conflict.

i want to execute a function when hittest is detected, instead of using the

```auto

fukx += (_root.newy-_x)/vel
	_x = Math.round(fukx);

```

for the movement. so the code would become:

```auto

onClipEvent (enterFrame) {
	if(this.hitTest(_root._xmouse,_root._ymouse,true))
		runThisFunction();
	else 
		runAnotherFunction();
}

```

the only problem with this is that the code within the function loops indefinately when used with hittest. How can i tell flash to just run the code within the function once?

Thanks!
