Flash ActionScript 2.0 Tutorial – Making Your Character Move with Arrow Keys

This is going to be a quick and ridiculously easy
tutorial. I will be making a part 2 to show how to make
your character face the way they’re moving but for now
this is just to help you get them actually moving. So
here we go, make your character whatever it may be. For
this tutorial I’m just going to make a box and I will be
referring to it from now on as “box.”

Either click on your box and press F8 or Right-
Click on it and click on Convert to Symbol. In the
options that appear make sure that Type is set to Movie
Clip, name it whatever you want and then of course click
OK. Now Once again while your box is selected press F9 or
Right-Click on it and click on Actions. In the Actions
Frame that appears type in:

onClipEvent(enterFrame){

if(Key.isDown(Key.UP)){
this._y-=5;
}

if(Key.isDown(Key.DOWN)){
this._y+=5;
}

if(Key.isDown(Key.LEFT)){
this._x-=5;
}

if(Key.isDown(Key.RIGHT)){
this._x+=5;
}

}

What your saying here is that if the UP arrow is
pressed the box will subtract 5 from it’s y position on
the field, therefore moving it up. If the DOWN arrow is
pressed it will add 5 to it’s y position and of course
move it down. Left and right are on it’s x position.
subtract for left and add for right. You can make your
character move faster by simply increasing the numbers.
Just for a test, switch all the 5s with 20s and you’ll
instantly see a difference.

Well that’s it for this tutorial. Now just press
CTRL + ENTER and test your movements. If for any reason
it doesn’t work or you are confused feel free to contact
me at [email protected] – Oh it’s real alright,
haha.


People also view

Leave a Reply

Your email address will not be published. Required fields are marked *