Here’s another old tutorial that I’ve bought over from the previous site, showing you how to create nice and simple 8 directional movement with rotation, handy for top down games such as RPG’s and the like.
I’ll probably carry this tutorial on at a later date to make a full game from it, until then, here’s the old one.
FrozenHaddock Tutorials: 8 Way Movement
In this tutorial, we’re going to create simple, 8-way, top-down movement. This is easy to implement and effective to use.

First, draw what you want to move.
You need to draw it facing upwards for the rotation to work.

Now select your character.

Hit F8, and convert the car to a movie clip.

Open the actions panel for the car.
To do this, select the movie clip and hit F9.

Now, this script creates the 8 way movement.
Unfortunately, this doesn’t make the character rotate.

This needs to be added into the previous script.

And lines need to be added into the existing script.
So, the full script you have on there should be this-
-
onClipEvent(load){
-
speed=5;
-
}
-
onClipEvent(enterFrame){
-
if(Key.isDown(Key.LEFT)&&Key.isDown(Key.UP)){
-
this._x-=speed;
-
this._y-=speed;
-
this._rotation=315;
-
}
-
else if(Key.isDown(Key.LEFT)&&Key.isDown(Key.DOWN)){
-
this._x-=speed;
-
this._y+=speed;
-
this._rotation=225;
-
}
-
else if(Key.isDown(Key.RIGHT)&&Key.isDown(Key.UP)){
-
this._x+=speed;
-
this._y-=speed;
-
this._rotation=45;
-
}
-
else if(Key.isDown(Key.RIGHT)&&Key.isDown(Key.DOWN)){
-
this._x+=speed;
-
this._y+=speed;
-
this._rotation=135;
-
}
-
else if(Key.isDown(Key.LEFT)){
-
this._x-=speed;
-
this._rotation=270;
-
}
-
else if(Key.isDown(Key.RIGHT)){
-
this._x+=speed;
-
this._rotation=90;
-
}
-
else if(Key.isDown(Key.UP)){
-
this._y-=speed;
-
this._rotation=0;
-
}
-
else if(Key.isDown(Key.DOWN)){
-
this._y+=speed;
-
this._rotation=180;
-
}
-
}
This should produce this
This can be used in many types of games, particularly RPG’s.
![[del.icio.us]](http://frozenhaddock.co.uk/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://frozenhaddock.co.uk/wp-content/plugins/bookmarkify/digg.png)
![[Google]](http://frozenhaddock.co.uk/wp-content/plugins/bookmarkify/google.png)
![[StumbleUpon]](http://frozenhaddock.co.uk/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Windows Live]](http://frozenhaddock.co.uk/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://frozenhaddock.co.uk/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://frozenhaddock.co.uk/wp-content/plugins/bookmarkify/email.png)


July 18th, 2008 at 2:19 am
Im getting this error when i enter the script into flash cs3, while using a actionscript 2.0 document.
‘)’ expected
For line 5:
if(Key.isDown(Key.LEFT)&&Key.isDown(Key.UP)){
July 18th, 2008 at 2:48 am
Hmm… I don’t see anywhere it would need a ), but it might just be the fact it’s 3am. I’ll check again when I’ve slept :)
July 18th, 2008 at 3:31 pm
Nope… no such luck… I have no idea why it’d return that error!
July 18th, 2008 at 9:24 pm
which version of flash are you using, because i only have MX, and the script is coming back with the following when i click test movie:
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 4: ‘{’ expected
onClipEvent(enterFrame)}
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 5: Unexpected ‘}’ encountered
if(Key.isDown(Key.LEFT))}
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 6: Statement must appear within on/onClipEvent handler
this._x-=speed;
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 7: Unexpected ‘}’ encountered
}
July 18th, 2008 at 9:25 pm
by the way, i haven’t added the rotation part in…
(i didn’t want it to rotate…)
July 18th, 2008 at 9:39 pm
it’s okay. it is sorted. just a typeing error. cool script by the way. ive been looking for one for nearly a year.
July 18th, 2008 at 10:23 pm
Really? There should be plenty out there!
Ah well, thanks :)
July 20th, 2008 at 1:58 am
getting the same error wolfhunter got. if i take away the rotation it works…any ideas? also I’d like to use the awsd keys….can’t figure it out. I have this right now.
onClipEvent(load){
speed=5;
}
onClipEvent(enterFrame){
if(Key.isDown(Key.”a”)){
this._x-=speed;
this._rotation=270;
}
else if(Key.isDown(Key.”d”)){
this._x+=speed;
this._rotation=90;
}
else if(Key.isDown(Key.”w”)){
this._y-=speed;
this._rotation=0;
}
else if(Key.isDown(Key.”s”)){
this._y+=speed;
this._rotation=180;
}
}
July 20th, 2008 at 2:21 am
For aswd keys, you’d use Key.isDown(#) replacing # with the appropriate ASCII code.
There’re a list of them here: http://blog.video-animation.com/2007/03/06/flash-8-ascii-keycodes/
July 20th, 2008 at 2:25 am
you are the best.
July 20th, 2008 at 3:00 am
yeah I keep getting
‘)’ expected
For line 5:
if(Key.isDown(Key.LEFT)&&Key.isDown(Key.UP)){
frustrating.
July 20th, 2008 at 5:36 pm
Hmm, I’ve no idea why that’s happening.
Let me investigate.
July 21st, 2008 at 9:51 am
I also got the ” ‘)’ expected For line 5 ” error. I fixed it by replacing the ” && ” with plain ” &&”. Probably its a syntax error do to the use of a ” ; ” within an if statement.
July 21st, 2008 at 10:10 am
Ah, I see!
Wordpress seems to take &’s and change them to the HTML friendly format…
It should indeed be &&, thanks for spotting it!
August 15th, 2008 at 7:30 am
I got
1087: Syntax error: extra characters found after end of program.
for line:
onClipEvent(load){
Why?
August 15th, 2008 at 9:06 am
Hmmm, I’m not too sure…
Are you definitely writing in AS2?
August 15th, 2008 at 6:01 pm
There are so many debugging errors in this tutorial.
August 15th, 2008 at 7:11 pm
What errors do you receive?
Are you writing in AS2?
Are you writing on a movie clip?
September 1st, 2008 at 1:11 am
The main problem I encountered, which seemed like the same one these others are encountering, is in the actionscript you have at the bottom of the screen. The errors are in lines 5, 10, 15, and 20. I found that by changing out the characters “&&” with “&&” I could get the file to work.
For people experiencing this problem, here’s the code:
onClipEvent(load){
speed=5;
}
onClipEvent(enterFrame){
if(Key.isDown(Key.LEFT)&&Key.isDown(Key.UP)){
this._x-=speed;
this._y-=speed;
this._rotation=315;
}
else if(Key.isDown(Key.LEFT)&&Key.isDown(Key.DOWN)){
this._x-=speed;
this._y+=speed;
this._rotation=225;
}
else if(Key.isDown(Key.RIGHT)&&Key.isDown(Key.UP)){
this._x+=speed;
this._y-=speed;
this._rotation=45;
}
else if(Key.isDown(Key.RIGHT)&&Key.isDown(Key.DOWN)){
this._x+=speed;
this._y+=speed;
this._rotation=135;
}
else if(Key.isDown(Key.LEFT)){
this._x-=speed;
this._rotation=270;
}
else if(Key.isDown(Key.RIGHT)){
this._x+=speed;
this._rotation=90;
}
else if(Key.isDown(Key.UP)){
this._y-=speed;
this._rotation=0;
}
else if(Key.isDown(Key.DOWN)){
this._y+=speed;
this._rotation=180;
}
}
September 1st, 2008 at 1:12 am
By all those ‘&’, I meant the little & amp part in your code above, but when I posted it the words changed lol
September 1st, 2008 at 8:09 pm
Lmao i made a lil stickman and it looks like he’s floating in space
and thanks for the new code aaron
so all that needed to be changed is ‘&&’ into ‘&&’?