# Problems with MOUSE position... HELP!

**URL:** https://forum.kirupa.com/t/problems-with-mouse-position-help/184052
**Category:** flash
**Created:** [April 1, 2006, 11:40am UTC](https://forum.kirupa.com/t/problems-with-mouse-position-help/184052 "2006-04-01T11:40:57Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Leo75](https://avatars.discourse-cdn.com/v4/letter/l/779978/32.png) [@Leo75](https://forum.kirupa.com/u/Leo75)
#### Post date: [April 1, 2006, 11:40am UTC](https://forum.kirupa.com/t/problems-with-mouse-position-help/184052/1 "2006-04-01T11:40:57Z")

</div>

HI there… I am trying to get the mouse position when u hover a button. The problem is that when u hover the same button vertically it gives the wrong position while when u do it horzontal, it works fine.  
I tried and tried to c what was wrong, but no idea so far.  
So if u guys could help, that would be nice.  
Here is the code, and the \*.fla is attached.  
Cheers  
Leo  
:player:

```auto

//function called to c where is the mouse, and get its position
where = function() 
{
 xdir = this._xmouse; 
 ydir = this._ymouse; 
 
 xdir = (xdir /10);
 xdir = Math.floor(xdir);
 xdir = xdir+8;
 
 ydir = (ydir /10);
 ydir = Math.floor(ydir);
 ydir = ydir+4;
 
// I am dividing the x position up to H. While the y position continues the same 
 if (xdir == 1)
 {
  xdir ="A";
 }
 
  if (xdir == 2)
 {
  xdir ="B";
 }
 
  if (xdir == 3)
 {
  xdir ="C";
 }
 
  if (xdir == 4)
 {
  xdir ="D";
 }
 
  if (xdir == 5)
 {
  xdir ="E";
 }
 
  if (xdir == 6)
 {
  xdir ="F";
 }
 
  if (xdir == 7)
 {
  xdir ="G";
 }
 
   if (xdir == 8)
 {
  xdir ="H";
 }
};
 
//call the first button.
cap._visible = false;
b1.onRollOver = function() {
 where();
 captionFN(true, xdir+" "+ydir, this);
 this.onRollOut = function() {
  captionFN(false);
 };
};
//call the second button.
b2.onRollOver = function() {
 where();
 captionFN(true, xdir+" "+ydir, this);
 this.onRollOut = function() {
  captionFN(false);
 };
};
//call the third button.
b3.onRollOver = function() {
 where();
 captionFN(true, xdir+" "+ydir, this);
 this.onRollOut = function() {
  captionFN(false);
 };
};
//call the forth button.
b4.onRollOver = function() {
 where();
 captionFN(true, xdir+" "+ydir, this);
 this.onRollOut = function() {
  captionFN(false);
 };
};
//call the fifth button.
b5.onRollOver = function() {
 where();
 captionFN(true, xdir+" "+ydir, this);
 this.onRollOut = function() {
  captionFN(false);
 };
};

captionFN = function (showCaption, captionText, bName) {
 if (showCaption) {
  this.createEmptyMovieClip("hoverCaption", this.getNextHighestDepth());
  cap.desc.text = captionText;
  cap._width = 7*cap.desc.text.length;
  cap._alpha = 75;
  // 
  if ((bName._width+bName._x+cap._width)>Stage.width) {
   xo = -2-cap._width;
   yo = -17;
  } else {
   xo = 2;
   yo = -17;
  }
  hoverCaption.onEnterFrame = function() {
   cap._x = this._xmouse+xo;
   cap._y = this._ymouse+yo;
   cap._visible = true;
  };
 } else {
  delete hoverCaption.onEnterFrame;
  cap._visible = false;
 }
};

```

---

<div class="post-metadata">

### Author: ![RichL](https://avatars.discourse-cdn.com/v4/letter/r/e79b87/32.png) [@RichL](https://forum.kirupa.com/u/RichL)
#### Post date: [April 1, 2006, 10:39pm UTC](https://forum.kirupa.com/t/problems-with-mouse-position-help/184052/2 "2006-04-01T22:39:31Z")

</div>

does this help…

xdir = **\_root**.\_xmouse;  
ydir = **\_root**.\_ymouse;

xdir = (xdir /10);  
xdir = Math.floor(xdir);  
xdir = xdir+ **1** ;

trace("ydir "+ydir);  
ydir = (ydir /10);  
ydir = Math.floor(ydir);  
ydir = ydir+ **1** ;

---

<div class="post-metadata">

### Author: ![Leo75](https://avatars.discourse-cdn.com/v4/letter/l/779978/32.png) [@Leo75](https://forum.kirupa.com/u/Leo75)
#### Post date: [April 3, 2006, 12:43pm UTC](https://forum.kirupa.com/t/problems-with-mouse-position-help/184052/3 "2006-04-03T12:43:44Z")

</div>

Thanks for the reply…  
But sadly i already tried that and it doesnt help…  
The reason why ydir = ydir+ **4** ; and xdir = xdir+ **8** ; its because the ZERO point is located at y=-4 and x=-8.  
And the \_root. is not gonna help me since the variables are not at the root.  
But thanks for the try.  
Any other idea?

Cheers!  
:thumb:  
Leo.

---

<div class="post-metadata">

### Author: ![RichL](https://avatars.discourse-cdn.com/v4/letter/r/e79b87/32.png) [@RichL](https://forum.kirupa.com/u/RichL)
#### Post date: [April 3, 2006, 10:41pm UTC](https://forum.kirupa.com/t/problems-with-mouse-position-help/184052/4 "2006-04-03T22:41:28Z")

</div>

are you not trying to identify your buttons as follows ?

A1 B1  
A2 B2 C2

does the attached fla not provide what you want?

isnt the problem that your this.\_xmouse and this.\_ymouse are calculated relative to the button it is called from?

maybe \_parent.\_xmouse and \_parent.\_ymouse would be better…then they will be relative to otra\_vez?

---

<div class="post-metadata">

### Author: ![Leo75](https://avatars.discourse-cdn.com/v4/letter/l/779978/32.png) [@Leo75](https://forum.kirupa.com/u/Leo75)
#### Post date: [April 3, 2006, 11:57pm UTC](https://forum.kirupa.com/t/problems-with-mouse-position-help/184052/5 "2006-04-03T23:57:15Z")

</div>

> are you not trying to identify your buttons as follows ?

A1 B1  
A2 B2 C2

does the attached fla not provide what you want?

isnt the problem that your this.\_xmouse and this.\_ymouse are calculated relative to the button it is called from?

maybe \_parent.\_xmouse and \_parent.\_ymouse would be better…then they will be relative to otra\_vez?

Hi there…  
Thanks for the reply…  
Actually i was able to solve the problem… and in a really easy way. Almost like a cheat. Some “hardcode” and that was it.  
Some logic. When the cursor hover the 1st button, then i assigned x=A y=1 when hovers the 2nd button (horizontal move) x=B y=1 and so on… then display that instead of calling for the mouse function that appeared to be inconsistent.  
Easy, no?  
And to think that i almost killed myself for that…  
But the problem is that i had to hard code EVERYTHING!  
But thanks anyway…  
Cheers!  
Leo.  
:thumb2:
