Basic Movement (arrow keys)
Apr.21, 2008 in
Flash Actionscript
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:
April 3rd, 2009 at 8:47 am
very good tut. how do you make him actually walk instead of slide?
April 3rd, 2009 at 2:18 pm
It would involve making the movieclip go to a certain frame with the walking animation on it, and rotating the object to the correct direction.
May 9th, 2009 at 7:25 pm
nice tutorial! really helped!
February 16th, 2010 at 1:08 pm
huh it wont work