Tutorials
Tutorials >> Arrow-Key Movement
Posted by fflash
In the process you will also learn about:
- Clip Events
- If statements
- Flash co-ordinates
So, I had better get started. Here is a link to what we will make.
As you can see, you can move the thing around with the arrow keys. The first step to this tutorial is creating the Movie Clip that we will be moving around. I drew this little fellow:

So, once you've drawn your thing, you can put it inside a Movie Clip. I assume you remember how to do that, but just in case you've forgotten, you have to select it all and press F8 to convert it to a symbol. Then choose Movie Clip, and call it ball, or circle, or something. You can make a little animation inside your Movie Clip if you want, like I did, but you don't have to.
Once you have done that, make sure you are on the main timeline, and select your Movie Clip. Then press F9 to open up your actions panel. then type this:
Well, what you have told Flash is, if the up key is being pressed, then its y position will be decreased by 5 whenever you enter a frame, or 30 times a second. It says this._y because it is referring to its own y postion. But you don't say "y", you say "_y".
So we can make it go up, and now we have to make it go the 3 other directions. Start by copying and pasting that line 3 times:
In the process you will also learn about:
- Clip Events
- If statements
- Flash co-ordinates
So, I had better get started. Here is a link to what we will make.
As you can see, you can move the thing around with the arrow keys. The first step to this tutorial is creating the Movie Clip that we will be moving around. I drew this little fellow:

So, once you've drawn your thing, you can put it inside a Movie Clip. I assume you remember how to do that, but just in case you've forgotten, you have to select it all and press F8 to convert it to a symbol. Then choose Movie Clip, and call it ball, or circle, or something. You can make a little animation inside your Movie Clip if you want, like I did, but you don't have to.
Once you have done that, make sure you are on the main timeline, and select your Movie Clip. Then press F9 to open up your actions panel. then type this:
- Code: Select all
onClipEvent (enterFrame) {
- Code: Select all
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= 5;
}
}
- Code: Select all
if (this happens) {
do this
}
- Code: Select all
if (a key is down(that is, the up key)){
do this
}
Well, what you have told Flash is, if the up key is being pressed, then its y position will be decreased by 5 whenever you enter a frame, or 30 times a second. It says this._y because it is referring to its own y postion. But you don't say "y", you say "_y".
So we can make it go up, and now we have to make it go the 3 other directions. Start by copying and pasting that line 3 times:
- Code: Select all
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= 5;
}
if (Key.isDown(Key.UP)) {
this._y -= 5;
}
if (Key.isDown(Key.UP)) {
this._y -= 5;
}
if (Key.isDown(Key.UP)) {
this._y -= 5;
}
}
- Code: Select all
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= 5;
}
if (Key.isDown(Key.DOWN)) {
this._y += 5;
}
if (Key.isDown(Key.RIGHT)) {
this._x += 5;
}
if (Key.isDown(Key.LEFT)) {
this._x -= 5;
}
}

Twitter