# Big troubles with onEnterFrame hitTesting

**URL:** https://forum.kirupa.com/t/big-troubles-with-onenterframe-hittesting/183402
**Category:** Uncategorized
**Created:** [March 26, 2006, 7:41pm UTC](https://forum.kirupa.com/t/big-troubles-with-onenterframe-hittesting/183402 "2006-03-26T19:41:23Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![roll4life](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@roll4life](https://forum.kirupa.com/u/roll4life)
#### Post date: [March 26, 2006, 7:41pm UTC](https://forum.kirupa.com/t/big-troubles-with-onenterframe-hittesting/183402/1 "2006-03-26T19:41:23Z")

</div>

hi all,

so, i’ve a movieclip with an over / out animation inside.  
when the mouse is over the movieclip, the over-animation should play,  
and vice versa…

i’m doing this with a hitTest nested in an onEnterFrame-funtion.

here is my code in the first keyframe:

```auto
this.onEnterFrame = function():Void {
    if( my_button.hitTest(_xmouse, _ymouse, true) ) {
        my_button.play();
    }    
}

```

ok, so far so good…but now the part with the BIG problem comes in:  
when the playhead reaches the stop()-keyframe inside my movieclip,  
where the animation should stop, it doesn’t stop due to the onEnterFrame-function, which fires permanent play()…

so, my questions is:  
how can i make movieclips with over / out - animations inside,  
which should play, when the mouse is over / isn’t over the movieclip,  
whithout loosing the precision of hitTesting?!?

maybe you know my problem, and maybe you even have solutions for this, it would be really cool, if somebody can help me out! :ko:

---

<div class="post-metadata">

### Author: ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)
#### Post date: [March 26, 2006, 8:43pm UTC](https://forum.kirupa.com/t/big-troubles-with-onenterframe-hittesting/183402/2 "2006-03-26T20:43:12Z")

</div>

try  
frame 1 of button MC;

```auto
stop();
this.onEnterFrame = function():Void {
	if (this.hitTest(this._parent._xmouse, this._parent._ymouse, true)) {
		play();
	}
};

```

frame 10;

```auto
stop();
delete this.onEnterFrame;
this.onEnterFrame = function():Void {
	if (!this.hitTest(this._parent._xmouse, this._parent._ymouse, true)) {
		play();
	}
};

```

frame 20;

```auto
gotoAndStop(1);
delete this.onEnterFrame;

```

but, why can’t you use onRollOver?

PS: Probably a better way… but it’s too early for me…

---

<div class="post-metadata">

### Author: ![roll4life](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@roll4life](https://forum.kirupa.com/u/roll4life)
#### Post date: [March 27, 2006, 6:53am UTC](https://forum.kirupa.com/t/big-troubles-with-onenterframe-hittesting/183402/3 "2006-03-27T06:53:15Z")

</div>

thx man, i’ll try it!

because the rollOver/rollOut events are not really precise, cause for example  
when i rollOver my movieclip really really fast, the event does not check for some reason, wheter my mouse is actually over the movieclip or not…

sry, for my english…i’m tryin my best 😉

---

<div class="post-metadata">

### Author: ![roll4life](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@roll4life](https://forum.kirupa.com/u/roll4life)
#### Post date: [March 27, 2006, 7:14am UTC](https://forum.kirupa.com/t/big-troubles-with-onenterframe-hittesting/183402/4 "2006-03-27T07:14:13Z")

</div>

hey man, hahaah…i tried it, and it worked perfect!!! big thx man…i nearly was goin mad on this…but you helped me…hhahahah

big thx man!
