# How do I set an area of a movie clip so I can tracks the mouse movement?

**URL:** https://forum.kirupa.com/t/how-do-i-set-an-area-of-a-movie-clip-so-i-can-tracks-the-mouse-movement/182664
**Category:** flash
**Created:** [March 20, 2006, 3:21pm UTC](https://forum.kirupa.com/t/how-do-i-set-an-area-of-a-movie-clip-so-i-can-tracks-the-mouse-movement/182664 "2006-03-20T15:21:21Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![impossible](https://avatars.discourse-cdn.com/v4/letter/i/cc9497/32.png) [@impossible](https://forum.kirupa.com/u/impossible)
#### Post date: [March 20, 2006, 3:21pm UTC](https://forum.kirupa.com/t/how-do-i-set-an-area-of-a-movie-clip-so-i-can-tracks-the-mouse-movement/182664/1 "2006-03-20T15:21:21Z")

</div>

How do I set an area of a movie clip so I can tracks the mouse movement?  
:crying:  
I don’t know actionscript, so I am asking for help with this.

1. I would like to make a MC invisible when the mouse is not over it.
2. I don’t want to use button controls because I have buttons nested within the MC.

Something like

if mouse x and y is in the area then MC is visible  
else MC is not visible

thanks

---

<div class="post-metadata">

### Author: ![Bokke](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Bokke](https://forum.kirupa.com/u/Bokke)
#### Post date: [March 20, 2006, 3:45pm UTC](https://forum.kirupa.com/t/how-do-i-set-an-area-of-a-movie-clip-so-i-can-tracks-the-mouse-movement/182664/2 "2006-03-20T15:45:25Z")

</div>

Use hittest! 😉

Place this piece of code on a frame.  
myMcInstance should be you movieclip instancename

```auto

this.onMouseMove = function(){
   if(myMcInstance.hitTest(_root._xmouse, _root._ymouse)){
      myMcInstance._visible = true;
   }
   else{
      myMcInstance._visible = false;
   }
}

```

[COLOR=#0000FF][/COLOR][COLOR=#0000FF][/COLOR][COLOR=#000000]\*\*\*\*[/COLOR][COLOR=#000000][/COLOR][COLOR=#000000][/COLOR][COLOR=#000000][/COLOR][COLOR=#0000FF][/COLOR]

---

<div class="post-metadata">

### Author: ![Bokke](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Bokke](https://forum.kirupa.com/u/Bokke)
#### Post date: [March 20, 2006, 3:51pm UTC](https://forum.kirupa.com/t/how-do-i-set-an-area-of-a-movie-clip-so-i-can-tracks-the-mouse-movement/182664/3 "2006-03-20T15:51:03Z")

</div>

whoops dubble post :cantlook:

---

<div class="post-metadata">

### Author: ![999](https://avatars.discourse-cdn.com/v4/letter/9/c5a1d2/32.png) [@999](https://forum.kirupa.com/u/999)
#### Post date: [March 20, 2006, 3:57pm UTC](https://forum.kirupa.com/t/how-do-i-set-an-area-of-a-movie-clip-so-i-can-tracks-the-mouse-movement/182664/4 "2006-03-20T15:57:18Z")

</div>

The first one is probably better since it wont use onEnterFrame and can tell if its hitting the object and not just the bounding box area like the hitTest.

```auto
mc._alpha = 0;
mc.onRollOver = function () {
	this._alpha = 100;
	this.onRollOut = function() {
		this._alpha = 0;
	}
}

```

```auto
mc._alpha = 0;
mc.onRollOver = function() {
	this.onEnterFrame = function() {
	if (this.hitTest(_root._xmouse, _root._ymouse)) 
		this._alpha = 100;
		else if (!this.hitTest(_root._xmouse, _root._ymouse)){
			delete this.onEnterFrame;
			this._alpha = 0;
		}
	}
}

```

Bokke. If the mc’s visibility is set to 0, how is it supposed to detect a hit the next time its rolled over?

//Edit

I missed that you had buttons in your mc. If thats the case you will need to have an invisible hit target in your movie under your buttons.

---

<div class="post-metadata">

### Author: ![Bokke](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Bokke](https://forum.kirupa.com/u/Bokke)
#### Post date: [March 20, 2006, 6:25pm UTC](https://forum.kirupa.com/t/how-do-i-set-an-area-of-a-movie-clip-so-i-can-tracks-the-mouse-movement/182664/5 "2006-03-20T18:25:34Z")

</div>

> [@999](#):
>
> Bokke. If the mc’s visibility is set to 0, how is it supposed to detect a hit the next time its rolled over?

:sure: Eh hehe… yeah, well there you have a point!

**edit:** So here’s a editted version of 999’s fla.  
It uses the onMouseMove event instead of the onRollOver event.  
This way you can see the difference between a button and its holder.  
Also: the code is much cleaner. ^^

---

<div class="post-metadata">

### Author: ![999](https://avatars.discourse-cdn.com/v4/letter/9/c5a1d2/32.png) [@999](https://forum.kirupa.com/u/999)
#### Post date: [March 20, 2006, 8:47pm UTC](https://forum.kirupa.com/t/how-do-i-set-an-area-of-a-movie-clip-so-i-can-tracks-the-mouse-movement/182664/6 "2006-03-20T20:47:40Z")

</div>

> [@Bokke](#):
>
> It uses the onMouseMove event instead of the onRollOver event.

Ahh, but your onMouseMove is running when the mouse is in motion no matter where its at. The onEnterFrame only runs when the cursor is hitting the movie clip.

> [@Bokke](#):
>
> Also: the code is much cleaner. ^^

Much improved over the mass quantity of font tags you originally had in your first script. 😉

---

<div class="post-metadata">

### Author: ![Bokke](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Bokke](https://forum.kirupa.com/u/Bokke)
#### Post date: [March 20, 2006, 9:18pm UTC](https://forum.kirupa.com/t/how-do-i-set-an-area-of-a-movie-clip-so-i-can-tracks-the-mouse-movement/182664/7 "2006-03-20T21:18:33Z")

</div>

> [@999](#):
>
> Ahh, but your onMouseMove is running when the mouse is in motion no matter where its at. The onEnterFrame only runs when the cursor is hitting the movie clip.

Yes that true, but the onEnterFrame is triggered by the onRollOver, so the user will think its a button. So to avoid that, you should use onMouseMove, onEnterFrame or some event like that. And doing it this way onMouseMove is less cpu intensive than an onEnterFrame, couse it only runs when moving the mouse.

Or is there a better solution ? 🙂

> [@999](#):
>
> Much improved over the mass quantity of font tags you originally had in your first script. 😉

:lol: Oh crap! And i hoped nobody saw that!

---

<div class="post-metadata">

### Author: ![999](https://avatars.discourse-cdn.com/v4/letter/9/c5a1d2/32.png) [@999](https://forum.kirupa.com/u/999)
#### Post date: [March 20, 2006, 9:44pm UTC](https://forum.kirupa.com/t/how-do-i-set-an-area-of-a-movie-clip-so-i-can-tracks-the-mouse-movement/182664/8 "2006-03-20T21:44:44Z")

</div>

> [@BOKKE](#):
>
> Yes that true, but the onEnterFrame is triggered by the onRollOver, so the user will think its a button.

Oh, I get what you mean. Yea I never even considered that. So I guess I’d do something like this.

```auto
mc._alpha = 0;
mc.hit.onRollOver = function() {
	this.useHandCursor = false;
    this.onEnterFrame = function() { 
    if (this.hitTest(_root._xmouse, _root._ymouse)) 
	_root.mc._alpha = 100;
        else {
	        delete this.onEnterFrame;
            _root.mc._alpha = 0;
        }
    }
}

```

> [@BOKKE](#):
>
> And doing it this way onMouseMove is less cpu intensive than an onEnterFrame, couse it only runs when moving the mouse.

In my case that would be alot more often then. I’ve always got the mouse cursor moving. Even when reading static pages. Nervous habit I guess.

> [@BOKKE](#):
>
> :lol:Oh crap! And i hoped nobody saw that!

I didnt see a thing! :cantlook:

---

<div class="post-metadata">

### Author: ![impossible](https://avatars.discourse-cdn.com/v4/letter/i/cc9497/32.png) [@impossible](https://forum.kirupa.com/u/impossible)
#### Post date: [March 20, 2006, 11:34pm UTC](https://forum.kirupa.com/t/how-do-i-set-an-area-of-a-movie-clip-so-i-can-tracks-the-mouse-movement/182664/9 "2006-03-20T23:34:43Z")

</div>

:ko: Hi Bokke and 999, thanks for all the help. I did not expect such speedy responses. You guys are cool.:rock:

Ok, Bokke I used the code you posted first, it worked like a charm. It is exactly what I needed. I have a visible = true button that would show the other buttons when it is rolled over.

999 in a couple of weeks when I have more time I will use your first code to add a millisecond fade (and maybe a slide-out from the home button) to my nav instead of its current show/hide.

Here is the FLA  
[http://www.impossiblemars.net/tempfree/flashnav2k6.fla](http://www.impossiblemars.net/tempfree/flashnav2k6.fla)  
[http://www.impossiblemars.net/tempfree/flashnav2k6.swf](http://www.impossiblemars.net/tempfree/flashnav2k6.swf)

Thanks A-lot
