00:00
00:00
Newgrounds Background Image Theme

Mekatov just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

As: Ways A Mc Can Follow Mouse

1,400 Views | 6 Replies
New Topic Respond to this Topic

As: Ways A Mc Can Follow Mouse 2005-06-28 14:31:19


AS: Main
Yet another, AS thread! This thread will teach you different ways for a MC to follow your mouse!

This is the first code. It makes the object follow your mouse:

onClipEvent (enterFrame) {
_y=_root._ymouse;
_x=_root._xmouse;
}

This code simple says that this objects _x and _y must follow the mouses _x and _y.

Now, if you want a code that makes a MC move only side-to-side with your mouse,
give it this code:

onClipEvent (enterFrame) {
_x=_root._xmouse;
_x=_root._xmouse;
}

This code simply says that only the MC's _x should only follow the mouse's _x.

This is a code that makes a MC move up and down with the mouse. Give it this code:

onClipEvent (enterFrame) {
_y=_root._ymouse;
_y=_root._ymouse;
}

This code simply says that only the MC's _y should only follow the mouse's _y.

I hope Denvish doesn't get mad for so many AS threads! XD

Response to As: Ways A Mc Can Follow Mouse 2005-06-28 14:47:44


how about
startDrag(this,true);

it's the easiest ;)

or did I miss you writing that?

Response to As: Ways A Mc Can Follow Mouse 2005-06-28 14:49:18


At 6/28/05 02:47 PM, Inglor wrote: how about
startDrag(this,true);

it's the easiest ;)

or did I miss you writing that?

Yea, you could do that, but for the last two codes, you couldnt do that. If you did, they would move in all directions and not just the ones I specified.

Response to As: Ways A Mc Can Follow Mouse 2005-06-28 14:53:04


of course you can ;)

1)your last codes had doubles, you could just delete the second line in both of them

to do this, you use the bounding triangle

on the X axis
startDrag(this,true,0,this._y,550,this._y);

on the Y axis
startDrag(this,true,this._x,0,this._x,400);

startDrag()
Availability
Flash Player 4.

Usage
startDrag(target:Object,[lock:Boolean, left:Number, top:Number, right:Number, bottom:Number]) : Void

Parameters
target The target path of the movie clip to drag.

lock A Boolean value specifying whether the draggable movie clip is locked to the center of the mouse position (true) or locked to the point where the user first clicked the movie clip (false). This parameter is optional.

left, top, right, bottom Values relative to the coordinates of the movie clip’s parent that specify a constraint rectangle for the movie clip. These parameters are optional.

Response to As: Ways A Mc Can Follow Mouse 2005-06-28 14:53:14


am i missing something or shouldn't it be

onClipEvent (enterFrame) {
_x=_root._xmouse;
}

instead of

onClipEvent (enterFrame) {
_x=_root._xmouse;
_x=_root._xmouse;
}

?

Response to As: Ways A Mc Can Follow Mouse 2005-06-28 14:54:21


At 6/28/05 02:53 PM, Inglor wrote: of course you can ;)

1)your last codes had doubles, you could just delete the second line in both of them

yeah, thats wat i was saying.

Response to As: Ways A Mc Can Follow Mouse 2005-06-28 14:54:27


At 6/28/05 02:53 PM, Bipin wrote: am i missing something or shouldn't it be

onClipEvent (enterFrame) {
_x=_root._xmouse;
}

Ooops! Yea, it should be that, but the other way still works.