[h1]
Basic Movement[/h1]
Okay, in this tutorial, I will teach you how to make a MC move.
*Notes*
I used Macromedia Flash MX 2004 for this tutorial.
This is the Timeline:

I expect you to know what a variable is,
30 FPS (frames per second) is what I always use for games, and you should too (it's nice and smooth).
Part one: Basic Movement ScriptOkay, I'll explain everything about basic movement.
The Syntax:When writing any script involving Movie Clips, we need to make them first! So, let's make a circle, like this one (20x20 circle, use the circle tool):


Okay, so we have a circle, now let’s convert it to a Movie Clip. To do this, select the circle and press F8. As soon as you press F8, it'll ask you to name it, let's name this one hero, and don't forget to check the 'Movie Clip' radial button!
This is what is should look like.

Okay, we have our hero Movie Clip, now we need to make him move! We'll use the arrow keys instead of W, A, S, D.
Select the hero Movie Clip on the Main Frame, and click the 'Actions' bar:

Okay, so, now we have a Movie Clip, but no actions on him! Let's add the movement script I've made:
onClipEvent (load) {
_root.up=true
_root.down=true
_root.left=true
_root.right=true
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP) && _root.up == true) {
_y-=5
}
if (Key.isDown(Key.DOWN) && _root.down == true) {
_y+=5
}
if (Key.isDown(Key.LEFT) && _root.left == true) {
_x-=5
}
if (Key.isDown(Key.RIGHT) && _root.right == true) {
_x+=5
}
}
Okay, now I have to break this up, and explain it:
onClipEvent (load) {
When the Movie Clip first enters the frame...
_root.up=true
_root.down=true
_root.left=true
_root.right=true
The variables up, down, left, and right get set to true.
onClipEvent (enterFrame) {
As long as the Movie Clip is in the current frame (there's only one frame!)...
if (Key.isDown(Key.UP) && _root.up == true) {
_y-=5
}
if (Key.isDown(Key.DOWN) && _root.down == true) {
_y+=5
}
if (Key.isDown(Key.LEFT) && _root.left == true) {
_x-=5
}
if (Key.isDown(Key.RIGHT) && _root.right == true) {
_x+=5
}
Here's the hard part, but this is what it means:
If the up key, is pressed down "if (Key.isDown(Key.UP)" and "&&" the variable _root.up is set to true "_root.up == true" then the Movie Clip hero's current _y position gets subtracted by 5, the _y+=5 stores the value of (x += 5) in the variable x, so that's how we get the Movie Clip to move! The same for the other; left, down, right and up. Here's a neat little table to explain the _x and _y positions:
| Position | _x | _y |
| +=5 | Right | Down |
| -=5 | Left | Up |
Final Product:
http://www.graphicaddicts.net/ssj//Basic%20Movement.swfOkay, so there’s our basic movement script and my explanation of it.
Please, save the .fla you've made. I'll basically use the exact same script in my hitTest tutorial.
hitTest tutorial is finished! Take a look:
hitTest Tutorial If you like this tutorial, please
Click Here to register.
Click the link below to download the Flash file for this tutorial.
Basic Movement FLA