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

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

Use hittest! :wink:

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


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]

whoops dubble post :cantlook:

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.

mc._alpha = 0;
mc.onRollOver = function () {
	this._alpha = 100;
	this.onRollOut = function() {
		this._alpha = 0;
	}
}
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.

: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. ^^

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.

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

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 ? :slight_smile:

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

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

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;
        }
    }
}

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.

I didnt see a thing! :cantlook:

: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.swf

Thanks A-lot