# Deactivating button depending on mouse position

**URL:** https://forum.kirupa.com/t/deactivating-button-depending-on-mouse-position/323244
**Category:** flash
**Created:** [June 22, 2011, 9:58am UTC](https://forum.kirupa.com/t/deactivating-button-depending-on-mouse-position/323244 "2011-06-22T09:58:18Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Luxmortem](https://avatars.discourse-cdn.com/v4/letter/l/9fc348/32.png) [@Luxmortem](https://forum.kirupa.com/u/Luxmortem)
#### Post date: [June 22, 2011, 9:58am UTC](https://forum.kirupa.com/t/deactivating-button-depending-on-mouse-position/323244/1 "2011-06-22T09:58:18Z")

</div>

Hello all,

I’ve been trying for a week to figure out a conflict between different buttons. The source of the conflict being that the buttons once rolled over appear over the others.

Finally I’ve found a possible solution by deactivating clips when the mouse moves to the left since the problem only appeared from right ==\> left movement of the mouse .

I’ve this code ready (I’ve found the mouse position part on this forum) :

[AS2]//General Cover Loader  
function startLoading(whichImage) {  
loadMovie(whichImage, “imgloader\_mc”);  
\_root.onEnterFrame = function() {  
infoLoaded = imgloader\_mc.getBytesLoaded();  
infoTotal = imgloader\_mc.getBytesTotal();  
percentage = Math.floor(infoLoaded/infoTotal\*truefalsefalse);  
percent\_txt.text = percentage+"%";  
if (percentage\>=truefalsefalse) {  
delete this.onEnterFrame;  
percent\_txt.\_visible = false;  
}  
};  
}

//General Button Function  
function cd\_button(button, cd\_cover) {

//button actions  
button.onRollOver = function() {  
this.gotoAndPlay(2);  
};  
button.onRollOut = function() {  
this.gotoAndPlay(13);  
};  
button.onRelease = function() {  
percent\_txt.\_visible = true;  
startLoading(cd\_cover);  
};

//button state regarding mouse position  
checkX = function (dx, oldVal, newVal) {  
if (oldVal\<newVal) {  
button.enabled = true;  
this.onMouseMove = function() {  
xdir = \_xmouse;  
};  
trace(“moving right”);  
} else if (oldVal\>newVal) {  
button.enabled = false;  
trace(“moving left”);  
}  
return newVal;  
};

```
this.watch("xdir",checkX);

this.onMouseMove = function() {
    xdir = _xmouse;
};

```

}

//Buttons & Images Links  
cd\_button(btn\_lifeandeath,“imgs/a\_life\_and\_death\_soundtrack\_front.jpg”);  
cd\_button(btn\_acadmetal,“imgs/academic\_metal.jpg”);  
cd\_button(btn\_diabolus,“imgs/diabolus\_ex\_machina\_front.jpg”);  
cd\_button(btn\_rose,“imgs/die\_rose\_selbsmord\_front.jpg”);  
cd\_button(btn\_puppy,“imgs/dont\_kick\_the\_puppy\_front.jpg”);  
cd\_button(btn\_dustin,“imgs/dustin\_the\_ground\_front.jpg”);  
cd\_button(btn\_tra\*\*\*\*,“imgs/if\_you\_dont\_want\_it\_trash\_it.jpg”);  
cd\_button(btn\_noisysilence,“imgs/listen\_to\_the\_noisy\_silence\_front.jpg”);  
cd\_button(btn\_grenades,“imgs/lumbers\_grenades.jpg”);  
cd\_button(btn\_marduk,“imgs/marduk\_rising\_front.jpg”);  
cd\_button(btn\_motherfloats,“imgs/mother\_float\_front.jpg”);  
cd\_button(btn\_guineapig,“imgs/something\_is\_wrong\_with\_the\_guinea\_pig.jpg”);  
[/AS2]

but it doesn’t deactivate the buttons when needed…

Any suggestion(s) ?

thanks in advance for your time
