# Constraining mouse trail

**URL:** <https://forum.kirupa.com/t/constraining-mouse-trail/62459>\
**Category:** flash\
**Created:** [August 27, 2004, 11:36pm UTC](https://forum.kirupa.com/t/constraining-mouse-trail/62459 "2004-08-27T23:36:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![phantomxc](https://avatars.discourse-cdn.com/v4/letter/p/9dc877/32.png) [@phantomxc](https://forum.kirupa.com/u/phantomxc)\
**Post date:** [August 27, 2004, 11:36pm UTC](https://forum.kirupa.com/t/constraining-mouse-trail/62459/1 "2004-08-27T23:36:24Z")

</div>

I got this mouse trail effect from one of the tutorials and I would like to be able to constrain it to specified perimeters. I couldn’t figure it out im too noob with action scripting "=/ but heres my code(I changed it a bit)…flash mx pro btw…

menu\_drag.onEnterFrame = function() {  
var xMouse = \_root.\_xmouse;  
if(Math.abs(xMouse - this.\_x) \< 1) {  
this.\_x = xMouse;  
} else {  
this.\_x -= (this.\_x-xMouse) / 1000;  
}  
}

so just incase you didn’t get what im trying to do…I dont want the menu\_drag to go past a certain point on the x axis… plz help me 🙂 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:** [August 28, 2004, 2:11am UTC](https://forum.kirupa.com/t/constraining-mouse-trail/62459/2 "2004-08-28T02:11:06Z")

</div>

depending on your framerate, you may want to use a bounding box and a hittest, if your framerate is high ie. 34+ hitTest might not work well … in which case you will need to pass more detection variables…

you may also want to try have two seperate functions, one for the drag event, and a totally seperate function for collision detection

but thats just me, im an oop kinda guy

---

<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:** [August 28, 2004, 3:43am UTC](https://forum.kirupa.com/t/constraining-mouse-trail/62459/3 "2004-08-28T03:43:59Z")

</div>

bah…i said im noob \>\_\<

---

<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:** [August 28, 2004, 4:45am UTC](https://forum.kirupa.com/t/constraining-mouse-trail/62459/4 "2004-08-28T04:45:19Z")

</div>

ok so I got a hitTest to work…kinda not really lol. I got it to basically bounce back once it hits the other object but it looses the mouse trailing effect…just slowly flys out of the flash…help me…\>\<

---

<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:** [August 28, 2004, 5:49pm UTC](https://forum.kirupa.com/t/constraining-mouse-trail/62459/5 "2004-08-28T17:49:10Z")

</div>

What you want to do is make a simple logical test to see if the dragged object’s \_x value is greater than a certain value (the point you do not want it to go past) and if it is, then set it back to that certain value.  
np

---

<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:** [August 28, 2004, 5:50pm UTC](https://forum.kirupa.com/t/constraining-mouse-trail/62459/6 "2004-08-28T17:50:34Z")

</div>

```auto
menu_drag.onEnterFrame = function() {
var xMouse = _root._xmouse;
if(Math.abs(xMouse - this._x) < 1) {
this._x = xMouse;
} else {
this._x -= (this._x-xMouse) / 1000;
}
furthestX = 100; //this will stop it going past 100.
if (this._x > furthestX) {
this._x = furthestX);
}
}

```

---

<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:** [August 29, 2004, 4:31am UTC](https://forum.kirupa.com/t/constraining-mouse-trail/62459/7 "2004-08-29T04:31:49Z")

</div>

little error in there but i figured it out \>\_\< hurt my brain lol thanks for helping though.
