PDA

View Full Version : mouse follow


bluefinger
06-19-2002, 03:35 AM
ok so I have this circle following my mouse and it's constrained to an x quadrant..and that's great.

But I want this to only happen when my mouse is within these paramaters. So when I enter the box, the circle follows my cursor on an x coordinate, but when I leave everything's back to normal.

I figure it's start drag, but how the hell do u do that?

Here's what I have:

onClipEvent (enterFrame) {
cX = this._x;
difX = cX-_root._xmouse;
setProperty (this, _x, cX-(difX/5));
if (_x<58) {
_x = 58;
}
if (_x>504) {
_x = 504;
}

poab
06-19-2002, 09:32 AM
Hi,

If you want the circle to follow rather than be stuck to the mouse you shouldn't use startDrag().

Make your circle a MC and inside that MC you need to create a control clip. Basically this is another MC with nothing in it but script. On frame one of the control MC:

if(_parent._x > _root._xmouse){
xDifference = _parent._x - _root._xmouse;
_parent._x = _parent._x - (xDifference / 2);
}
if(_parent._x < _root._xmouse){
xDifference = __root._xmouse - _parent._x;
_parent._x = _parent._x + (xDifference / 2);
}
if(_parent._y > _root._ymouse){
yDifference = _parent._y - _root._ymouse;
_parent._y = _parent._y - (yDifference / 2);
}
if(_parent._y < _root._ymouse){
yDifference = __root._ymouse - _parent._y;
_parent._y = _parent._y + (yDifference / 2);
}

On frame two of the control MC:

gotoAndPlay(1);


If you want to constrain the area that the circle follows the mouse over surround the whole of frame one's code with something like this:

if((_root._xmouse >= 10) && (_root._ymouse >=10) && (_root._xmouse <= 250) && (_root._ymouse <= 250){
//FRAME ONE CODE HERE
}

cheers

poab
06-19-2002, 09:34 AM
Sorry, forgot to add:

If you want it to return to it's original position, you need to put in an else statement after the if it's within these coordinates bit. Inside there instruct the circleMC back to it's starting position.

cheers.

farafiro
06-19-2002, 10:00 AM
nice one POAP
but u can make live easier byt making a hidden MC in the same parameters and .....//on the hidden MC
onClipEvent(enterFrame){
if(this.hitTest(_root._xmouse,_root._ymouse,true)) {
//the following code here
}
}
or u can make the followin code in a function and call it