# Move a mc by buttons

**URL:** <https://forum.kirupa.com/t/move-a-mc-by-buttons/109120>\
**Category:** Uncategorized\
**Created:** [May 2, 2004, 10:54am UTC](https://forum.kirupa.com/t/move-a-mc-by-buttons/109120 "2004-05-02T10:54:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![z\_nicz](https://avatars.discourse-cdn.com/v4/letter/z/71e660/32.png) [@z\_nicz](https://forum.kirupa.com/u/z_nicz)\
**Post date:** [May 2, 2004, 10:54am UTC](https://forum.kirupa.com/t/move-a-mc-by-buttons/109120/1 "2004-05-02T10:54:42Z")

</div>

Hi again!

Now I have another question, how do I bind a button to a mc. I have four buttons that should move a mc in four diffrent directions, I want the mc to move like the code below by pressing on the buttons. What should I do?

[COLOR=Navy]onClipEvent (enterFrame) {  
if (Key.isDown(Key.UP)) {  
speed += .3;  
}  
if (Key.isDown(Key.DOWN)) {  
speed -= .25;  
}  
0.6xspeed  
if (Math.abs(speed)\>10) {  
speed \*= .9;  
}  
if (Key.isDown(Key.LEFT)) {  
\_rotation -= 4.5;  
}  
if (Key.isDown(Key.RIGHT)) {  
\_rotation += 4.5;  
}  
speed _= 0.987;  
x = Math.sin(\_rotation_(Math.PI/180))_speed;  
y = Math.cos(\_rotation_(Math.PI/180))_speed_-1;  
if (!\_root.move.hitTest(\_x+x, \_y+y, true)) {  
\_x += x;  
\_y += y;  
} else {  
speed \*= -.6;[/COLOR]  
}
