# Key press in increments?

**URL:** <https://forum.kirupa.com/t/key-press-in-increments/97797>\
**Category:** Uncategorized\
**Created:** [December 29, 2003, 5:48pm UTC](https://forum.kirupa.com/t/key-press-in-increments/97797 "2003-12-29T17:48:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)\
**Post date:** [December 29, 2003, 5:48pm UTC](https://forum.kirupa.com/t/key-press-in-increments/97797/1 "2003-12-29T17:48:29Z")

</div>

Happy Holidays Kirupians!

Back from a quick xmas break with this question:

WHY AM I NOT OUT SNOWBOARDING?! THERE ARE 20 NEW INCHES OF POWDER ON THE MOUNTAIN! ARGH! WORK SUCKS!

But to a more forum-appropriate question:

I have this prototype function:  
[AS]  
MovieClip.prototype.moveRight = function() {  
// when it enters the frame  
this.onEnterFrame = function() {  
oldx = newx;  
// if timelineMC.\_x less than or equal to howFarRight  
if (timeline.\_x\<=howFarRight) {  
// delete the onEnterFrame so it can’t scroll  
delete this.onEnterFrame;  
} else {  
// else keep scrolling it  
\_global.scrolling = true;  
timeline.\_x -= speed;  
newx = timeline.\_x;  
\_global.timex = newx-oldx;  
}  
};  
};  
[/AS]

and call it this way:

[AS]  
left.onPress = moveLeft;  
right.onPress = moveRight;  
[/AS]

Now, I would like to also be able to use the left and right arrow keys to accomplish the same thing but I’m not sure how to script it since prototypes aren’t really my thing and since I used MCs instead of buttons (so I can’t say “on (release, keyPress\<LEFT\>)” etc.).

I tried using this:  
[AS]  
this.onKeyDown = function() {  
if (Key.getCode() == Key.LEFT) {  
moveLeft();  
}  
if (Key.getCode() == Key.RIGHT) {  
moveRight();  
}  
};  
Key.addListener(this);  
[/AS]

which works great except that it scrolls the whole thing all at once. Is it possible to put some kind of increment in there so that on a key press it only moves a certain amout of pixels?

Thanks for any help!
