Constraining mouse trail

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

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

bah…i said im noob >_<

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…><

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

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

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