What you will learn: How to move a MovieClip around in flash using the arrow keys.

What you will need: a movieclip that you wish to move around.

1. There is really only one step to this tutorial. Just put this code onto your MovieClip. All code is explained.

  • onClipEvent(enterFrame){//every frame
    if (Key.isDown(Key.UP)){//if the up key is down
    _y-=8//move character 8 pixels up
    }
    if (Key.isDown(Key.DOWN)){//if the down key is down
    _y+=8//move character 8 pixels down
    }
    if (Key.isDown(Key.RIGHT)){//if the right key is down
    _xscale = 100;//makes character face right
    _x+=8//move character 8 pixels to the right
    }
    if (Key.isDown(Key.LEFT)){//if the left key is down
    _xscale = -100;//makes character face left
    _x-=8;//move character 8 pixels to the left
    }
    }

2. Here is what it should look like.

Related posts:

  1. List of Flash Key Codes
  2. Code Bits: hitTest
  3. Code Bits: Timeline