Object Follows mouse in Flash
Hey guys, this is Mads 101. Today I got another special guest showing you how to do something special in Flash. So, uh, here we go.
Hey guys, so in, uh, for today's tutorial, I'm going to, uh, make an object follow the mouse with, uh, Flash ActionScript. I'm using Flash ActionScript 2.0.
So I'll start off by drawing a little object, then I'll convert that to a movie clip. I'll name it "Smiley Face." Now I'll open up the actions, which, uh, which will be how you actually make it follow the mouse.
So I'll start off by writing "onClipEvent(enterFrame)," which will make it so that it, uh, every time, every, uh, or the frames per second is 12. So 12 times per second, it should, uh, it should do that.
Within the inside the brackets, so I'll write in "x = _root._x + _dxMouse." And what this means is that it sets a variable called X, and that equals, uh, the X Mouse in the, uh, _root.
So then I'll do "y = _root._y + _dyMouse," and this does the same thing for the, um, Y component of the, uh, of the mouse.
Now I'll make it so that it, um, moves. So I'll do "x += x - _dx;" then I'll do "y += _Y - _dy."
Now, if I test the movie, it should be following the mouse. And I'll, I'll bump up the, uh, frames per second to 24 so it looks better, smoother.
And now, it's not using yet—it's only, uh, on the mouse. So I'll, I'll make it so that it eases by dividing the thing that it's, uh, the ratio there, or the, uh, little subtraction thing, and I'll divide the whole thing by 10.
I'll do that for both the X and the Y. So now, if I, if I test the movie, it should be following the mouse; it should be easing to the mouse.
And, uh, that's all. Um, and there'll be, uh, the code will be in the description of the video. And, uh, that's all.