How To Move A Movieclip With The Arrow Keys

Hey! This is somthing simple…But here it is:

Step 1 ~ Make an MC (MovieClip) and call it “player”.

Step 2 ~ Copy and paste this code to it:

_______________________________________________________________

onClipEvent (enterFrame) {
 //This is to see if the key “RIGHT” is being pressed.
 if (Key.isDown(Key.RIGHT)) {
  //This is saying how much it will move and what direction it will move in.
  this._x += 5;
 }
 //Seeing if the key “LEFT” is being pressed.  
 if (Key.isDown(Key.LEFT)) {
  //This is saying what speed and what direction it is moving in.
  this._x -= 5;
 }
 //Seeing if the key “UP” is being pressed…I am getting tired of this.  
 if (Key.isDown(Key.UP)) {
  //Saying what direction it will move in and how many pixels.
  this._y -= 5;
 }
 //Same thing! :D  
 if (Key.isDown(Key.DOWN)) {
  //you can play around with the _y and += to see what direction
  //you can make it move
  this._y += 5;
 }
}

_______________________________________________________________

There you go! Hopefully that works for you. Any questions, just leave a comment.

Leave a Reply