Following Cursor

April 17, 2007

Assumed knowledge: Basic Flash Navigation, Object creation and Basic Actionscript knowledge
Concepts Covered: Commanding a movieclip to follow the X and Y values of your cursor

This is probably my favourite little Flash program that I have made. Its so simple, anyone can do it.

Load up Flash and create a movieclip with something clearly visible inside it. All that?’s left now is to insert the code.

This is the code that you put into your movieclip.

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

Lets look at this code.

onClipEvent tells the program that once an event happens in the movieclip then?’. The condition in the brackets is that event. In this case once the current frame is entered. The { sets us up for the action which is about to occur when the frame is entered. This?’ is referring to the current movieclip which the code is in. ._x is referring to the x value. Equals sets the value to be the same as the other value. _ root._xmouse looks for the x value of the mouse. The ; closes off the action. The code on the next line is the same but for the y axis. The { closes off the code.

What this means as a whole is that once the frame is entered then the x and y values of the current movieclip are the same as that of the mouse.

You can do what I like to do and edit your movieclip so that it looks pretty. I made a little planet and a moon in my example which can be found here:

Downloadable Source Files

If you enjoyed this post, then make sure you subscribe to my RSS Feed

Tags: , , ,
Posted in Tutorials |



Related Entries




No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Have you checked out my gaming personal blog yet? No! Then take a squiz: