# When mouse is rollOut?

**URL:** <https://forum.kirupa.com/t/when-mouse-is-rollout/24816>\
**Category:** Uncategorized\
**Created:** [July 5, 2003, 8:16am UTC](https://forum.kirupa.com/t/when-mouse-is-rollout/24816 "2003-07-05T08:16:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neo\_Geo](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@Neo\_Geo](https://forum.kirupa.com/u/Neo_Geo)\
**Post date:** [July 5, 2003, 8:16am UTC](https://forum.kirupa.com/t/when-mouse-is-rollout/24816/1 "2003-07-05T08:16:38Z")

</div>

i got a MC that follows mouse movement with easing in y-axis.  
this is the MC actionscript:  
[AS]  
onClipEvent (enterFrame) {  
\_y += (\_parent.\_ymouse-\_y)/5;  
}  
[/AS]

but i only want it to follow the mouse only when the mouse is on top of this MC.  
using that script, the MC will follow no matter where i placed the mouse.  
can anyone help me to modify it?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 5, 2003, 8:32am UTC](https://forum.kirupa.com/t/when-mouse-is-rollout/24816/2 "2003-07-05T08:32:57Z")

</div>

this should do it:

[AS]  
//place this on the main timeline  
my\_mc.onRollOver = function(){  
my\_mc.onEnterFrame = function(){  
my\_mc.\_y += (\_ymouse - \_y)/5  
}  
}  
my\_mc.onRollOut = function(){  
delete my\_mc.onEnterFrame;  
}  
[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 5, 2003, 8:45am UTC](https://forum.kirupa.com/t/when-mouse-is-rollout/24816/3 "2003-07-05T08:45:22Z")

</div>

urm. it move when my mouse is on top of that MC  
but it didnt follow the mouse. it just go straight down

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 5, 2003, 4:00pm UTC](https://forum.kirupa.com/t/when-mouse-is-rollout/24816/4 "2003-07-05T16:00:12Z")

</div>

[AS]my\_mc.onRollOver = function() {  
this.onEnterFrame = function() {  
this.\_y += (this.\_parent.\_ymouse-this.\_y)/5;  
};  
};  
my\_mc.onRollOut = function() {  
delete this.onEnterFrame;  
};[/AS]

:thumb:

[edit]

[AS]my\_mc.onRollOver = function() {  
this.onEnterFrame = function() {  
this.\_y += (this.\_parent.\_ymouse-this.\_y)/5;  
};  
};  
my\_mc.onRollOut = function() {  
var fY = this.\_parent.\_ymouse;  
this.onEnterFrame = function() {  
this.\_y += (fY-this.\_y)/5;  
};  
};[/AS]

That will give you a smoother onRollOut 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 5, 2003, 4:21pm UTC](https://forum.kirupa.com/t/when-mouse-is-rollout/24816/5 "2003-07-05T16:21:46Z")

</div>

ok… works great. thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 5, 2003, 10:50pm UTC](https://forum.kirupa.com/t/when-mouse-is-rollout/24816/6 "2003-07-05T22:50:38Z")

</div>

```auto
my_mc.onRollOver = function() {
        this.onEnterFrame = function() {
                this._y += (_root._ymouse-this._y)/5;
        };
};
my_mc.onRollOut = function() {
        var fY = _root._ymouse;
        this.onEnterFrame = function() {
                this._y += (fY-this._y)/5;
                if(this._y>(fY-.2)) delete this.onEnterFrame;
        };
};

```

Please don’t use \_parent. Use \_root instead. What If the mc that folows the mouse is inside another mc?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 6, 2003, 2:03am UTC](https://forum.kirupa.com/t/when-mouse-is-rollout/24816/7 "2003-07-06T02:03:16Z")

</div>

Good catch [m], thanks 🙂 I just have a habit of not using \_root, but in this case it would actually be best to use \_root.
