Best viewed in Firefox

Awesty Productions

Moving Movie Clips with the Arrow Keys Tutorial

August 26th, 2006 by awesty

In this tutorial I will teach you how to move a MovieClip around the stage with the arrow keys using actionscript.

What you need to know:

  • Basic flash skills. Like using all the tools and everything.
  • It would help if you had knowledge of another programming language like PHP, JavaScript or C++.

I am using Flash 8 for this tutorial, but you can use Flash MX 2004 if you want.

Lets begin!



Thanks for taking the time to view this tutorial! :D

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • del.icio.us
  • digg
  • Furl
  • MyShare
  • NewsVine
  • Netscape
  • Reddit
  • Simpy
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

RSS feed | Trackback URI

70 Comments »

2006-09-04 18:55:44

[…] You need to have taken my ‘Moving MovieClips with the ArrowKeys tutorials. Click here veiw it now. […]

Comment by Greg Subscribed to comments via email
2007-06-13 17:48:36

Hi, used your tutorial, really easy and managed to finish my flash. Reckon you save me about 4hrs of searching. Spent ages lookin for and usin other sites. nice one!

 
 
Comment by lol_i_pop
2006-09-10 20:57:57

good tutorial i spose

 
2006-09-16 19:13:27

[…] You need to have taken my ‘Moving MovieClips with the ArrowKeys tutorial’. Click here veiw it now. […]

 
Comment by Danny
2006-09-16 20:15:19

Ye, it was pretty good
the only thing is that its hard to remember
i had to copy and paste on word to use it now
mabey explain in detail the smaller things and
possilbly give examples of other ways to use
bits of that code.
Otherwise it was great:D tnx man

 
Comment by awesty
2006-09-16 23:14:54

I had the same problem when I was trying to learn.
All you have to remeber is that most of it is if statements like:
if(this happens){
do this;
}
Like if you brain ran on actions script this would be for the hungry code:
if(I am hungry){
eat;
}
And you just keep messing around with the same code until you think you understand it ;)

 
Comment by samir lotfi
2006-09-17 06:32:05

Thank you so much you help me a lot
to learn action
you are great

 
Comment by Johny
2006-09-24 18:17:09

is there a place on the web that I can learn action script easily?
BTW the if you do this,do this explanation was cool
thnks

 
Comment by awesty
2006-09-24 22:58:55

I don’t really understand the second half of that :?

 
2006-10-15 16:17:24

[…] This tutorial will be a whole lot easier if you have already taken my Moving MovieClips with the arrow keys, Making walls with hitTests and Making a health system tutorials since alot of the script used in those will be used in this tutorial so I won’t go into as much detail with them as I might with the rest of the script. […]

 
Comment by Alex
2006-10-18 03:50:08

i was wondering how do i make my character face the directions when i move him?

 
Comment by awesty
2006-10-18 17:39:59

You can find that in this tutorial.

 
Comment by Alex
2006-10-19 08:33:49

i dont see it in this tutorial also i need my character to have a walking animation in the direction hes facing and so far on the net i cant find one that works thanx

 
Comment by Alex
2006-10-19 08:34:52

sorry nvm did not see that u had link in ur message

 
Comment by m
2006-10-27 07:30:40

what?

 
Comment by awesty
2006-10-27 11:41:43

What what?

 
Comment by H
2006-10-27 12:33:45

what..ahh the simple asking words ;)

 
Comment by R
2006-10-31 11:44:34

What when?

 
Comment by Vikas Mathur
2006-10-31 16:39:31

thanks it working and walking i make a game with this I hide the walls and ask user to exit from this game

 
Comment by you
2006-11-06 14:35:04

…..

 
Comment by andrew
2006-11-07 02:29:47

eh… it dont work

 
Comment by awesty
2006-11-07 10:49:20

Make sure you didn’t miss any steps.

 
2006-11-11 14:36:44

[…] You should have taken my Moving MovieClips with the arrow keys tutorial because I will not be explaining that code. […]

 
Comment by Webber
2006-11-16 13:39:39

hi! once agian thanks! but theres a problem, im making simple little game that you have to jump on platforms etc ive taken out moving up or down and replaced with jump, i can make it move in the air BUT, i want it to drop to the bottom of the screen wen u go off of the platform! code? or what?

 
Comment by Slash
2006-11-16 22:24:06

it doesn’t work for me I tried it like 10 times :(

 
Comment by awesty
2006-11-17 09:32:05

@Webber: http://www.awestyproductions.c.....m-jumping/

@Slash: I’ll need more information if you want me to help you.

 
Comment by Slash
2006-11-18 06:03:58

i mean, I made a motion tween, and a charcter “man” MC, but the motion tween keeps going on and on (Which is him walking) but I want it to act as if hes only walking when you hit left and right arrow keys, so he isn’t just walking while he is standing still

 
Comment by awesty
2006-11-18 09:47:17

um, if you follow the tutorial there is no motion tweening involved.

 
2006-11-27 19:04:42

[…] This makes the MC move left and right. I have explained that is a fair few of my tutorials, so I am not going to explain it here. If you want an explanation try this tutorial. […]

 
Comment by sam
2006-11-29 07:10:39

where did u learn to understand actionscript…
i mean i read all the comments yet i still dont understand, where to find?

 
Comment by awesty
2006-11-29 07:25:32

Just tutorials like this one. I can remember taking a tutorial like this and thinking exactly the same thing.

All most of these codes are made up of are if statements and variables.

i = 5;
if(i == 5){
trace(”i is equal to 5″);
}

If you put that on a frame, it would output “i is equal to 5″. Just keep messing around with stuff like that and it will eventually come.

When you take a tutorial, if you just forget about it afterwards you will probably forget it, but if you play around with it you will learn more about it.

Also try pushing F1 for flash help ;)

 
Comment by sam
2006-12-01 14:28:49

hey thanks for the advice here are some codes i found…well better, it has a rotation faceing the way you want it to be:
onClipEvent (enterFrame) { if (Key.isDown(Key.DOWN)) { _y -= -10; _rotation = 90; }}
onClipEvent (enterFrame) { if (Key.isDown(Key.LEFT)) { _x -= 10; _rotation = 180; }}
onClipEvent (enterFrame) { if (Key.isDown(Key.RIGHT)) { _x -= -10; _rotation = 0; }}
onClipEvent (enterFrame) { if (Key.isDown(Key.UP)) { _y -= 10; _rotation = -90; }}

 
Comment by awesty
2006-12-01 16:22:04

That is completely different and have to many clip events, you only need one.

I have a tutorial for that kind of movement.

 
Comment by RedV
2006-12-02 05:15:38

how do u make the character stop when he gets to the edge?

 
 
Comment by RedV
2006-12-02 11:32:45

haha thanks i didnt think to look at the other tutorials i feel stupid
sorry

 
Comment by alex
2006-12-04 03:48:21

great tutorial, im just instal;lin flash and its been goin for ages and only on 80%

lol im gonna make a fightin game,with yur tutorials i hope its gonna b easy.

 
Comment by teeno15
2006-12-06 22:05:40

i thght this tutorial was really cool for a newbie like me thnx

 
Comment by RDB2006
2006-12-11 00:17:57

gd luck alex, but it wont be begginer level.

 
Comment by bob
2006-12-12 10:32:25

it doesn’t show anything!

 
Comment by andy
2006-12-15 22:41:30

How do you make it so that, let’s say, your car turns instead of just sliding

 
Comment by awesty
2006-12-16 17:21:14

@Bob: Make sure you have the latest flash player.

@Andy: I might do a tutorial on that, but here is a good one on a friend of mines site. ;)
http://www.graphicaddicts.net/.....832.0.html

 
2006-12-17 12:18:50

[…] That looks longer than it actually is. It is all just repeated though, with a few numbers changed around. The first part you should already know, but if not, you can find an explanation on it in this tutorial. LINK. The part I will be explaining in this tutorial is this part: […]

 
Comment by Vytas
2006-12-18 02:46:29

I want to add borders to the file how d0 i do this . and i want him to bounce off if he gets to it

 
Comment by awesty
 
Comment by KIM
2006-12-22 17:50:16

how can i make my char jump if i press up?
thnx awesty

 
 
Comment by tyler
2007-01-16 11:23:13

hey awesty i was just wondering if there was a code i could use to make the arrow keys control the camera views of what ever it is focusing at.

for example: on runescape, you can use the left and right arrow keys to move the camera view all around your character and when you press the top arrow key it can go as far as a birds eye view of your character.

so basically i was wondering if you could get me a code that works like that.

thx

 
Comment by tim
2007-01-22 06:39:31

hey, for some reason i can’t get my movie clip to stop at any frames. is there some other way to stop playback while at the same time using code from the hit test 2 tutorial?

 
Comment by fy
2007-01-23 13:53:03

It would be good if this tutorial code can set the boundary for the slider so that it will not “fall” out of the screen. :)

 
Comment by Crap_Face
2007-01-26 09:54:15

GOOD! But one thing. This Tute was sposet’ to be about a health system not a move da arrow keys… It is like the control a ball tute! You Creep Me out. YIKES! I an a male you know!

 
Comment by awesty
2007-01-26 11:20:13

@tyler: Try googling vcam.

@tim: Try stop();

@fy: Try this page:

http://www.awestyproductions.com/tutorials/

There are tutorials there for that.

@Crap_face: No it wasn’t. Read the title. >_>

 
Comment by Anonymous2
2007-02-02 12:31:06

Can Someone Please HELP!
I keep getting the same error!

**Error** Symbol=man, layer=Layer 1, frame=1:Line 1: Clip events are permitted only for movie clip instances
onClipEvent(enterFrame){

Total ActionScript Errors: 1 Reported Errors: 1

 
Comment by Jacob Daniels
2007-02-14 00:00:47

Hey, I’ve learnt this code and it’s pretty easy, great tutorial xD Thanks, but!
I write it down exact and this comes in

“**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Clip events are permitted only for movie clip instances
onClipEvent(enterFrame){

Total ActionScript Errors: 1 Reported Errors: 1″

 
Comment by Jacob Daniels
2007-02-14 00:16:19

Oh and the code makes Up mean down and Down mean up.

 
Comment by Jacob Daniels
2007-02-14 00:32:26

Oh how I need a dunce cap! I’ve fixed it, just turned out I had a circle not a square

 
Comment by awesty
2007-02-14 16:43:44

@Anonymous2: Your not supposed to put the code on the frame.

@Jacob: It shouldnt matter if you have a circle or a square. The error you posted was because you put the code on a frame, not an MC.

 
Comment by awscherb
2007-02-20 05:46:12

can you please make a scrolling tutorials?

 
Comment by chad
2007-03-10 16:40:00

i was wonder if theres a way to make it where if i make my character walk into a wall like in the hittest tut could i make it go to a whole new frame

 
Comment by awesty
2007-04-05 13:08:03

@awscherb: Yes.

@Chad: Yes.

if(this.hitTest(something)){
_root.gotoAndStop(FRAME);
}

 
Comment by KIM Subscribed to comments via email
2007-05-27 22:28:02

HEEY!! throught the moving with the arrow keys and the gotoAndStop(); thingy i made some thing my self!!!!

i KNOW hot to get different charaters in 1 game i know how to pick’em!!!!

thnx alot
KIM

 
Comment by destructin Subscribed to comments via email
2007-07-23 03:59:01

nice, yeah but i wanted to know how to make the character look like he’s walking. thanks

Comment by destructin Subscribed to comments via email
2007-07-25 05:32:31

never mind, i already know

 
 
Comment by Isaac Subscribed to comments via email
2007-11-19 12:01:36

it wont work theres always a problem with the first line of code

 
Comment by Horhey Subscribed to comments via email
2008-01-08 12:54:28

I don’t know if he has posted this in a different tut but I edited that so there was a bit of gravity.

onClipEvent (load) {
power = 0.2;
yspeed = 0;
xspeed = 0;
friction = 0.95;
gravity = 0.1
}

onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
xspeed -= power;
}
if (Key.isDown(Key.RIGHT)) {
xspeed += power;
} if (Key.isDown(Key.UP)) {
yspeed -= power;
}
if (Key.isDown(Key.DOWN)) {
yspeed += power;
}
xspeed *= friction;
yspeed += gravity;
_y += yspeed;
_x += xspeed;
}

 
Comment by james Subscribed to comments via email
2008-03-08 02:40:32

how do you make it so if your character is standing still.. let’s say if you press right he will run right!

 
Comment by Juice Subscribed to comments via email
2008-03-31 05:10:03

Yo, do you have a tut for damaging someone in a turn based battle, like getting shot by something and having your health drained

 
Comment by Taylor Haberle
2008-04-19 06:17:59

Hello,

I have Adobe CS3, so I assume this is ActionScript 2.0

By the way, for line one, in {enterFRAME} and it was frame 1, would I type in {1}

 
Comment by rudydbooty
2008-07-16 04:21:26

how do i add.. a friction…?

 
Comment by lucasfth Subscribed to comments via email
2008-08-18 01:25:24

THANKS A LOT!!!

I kept like 3 months looking for hitTest (if you wanna know, i was desinging an MMORPG, but the hitTests never worked…), until i found this tut… well the ends was frustrating, it didn’t worked, buut then i realized that i hadn’t made the instance name :)… lol… 3 months, just by an instance name…

holy $|-|1T!

 
Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> in your comment.