[Flash CS4 (AS2)] Help with acceleration/deceleration on arrow key movement

Hi! I know it’s probably an annoying thing to hear but I’m almost completely new to Actionscript, I have a good knowledge of Flash for motion-graphics-related animation but want to start learning script to add interactive elements to my movies. I’m just looking at guides one by one trying to figure out what each bit of code means before I move on (AS is the first coding language I’ve attempted to learn).

Right now I’m looking at some of the numerous “make-your-own-platform-game” guides on the internet, and I’m trying to make an MC move from side to side with the arrow keys. I’m trying to get acceleration/deceleration to work so the movement looks a little less wooden.

here’s the code I’m using so far:

var run = 1;

onEnterFrame = function () { 
    if (run < 10) {run += 1;}
};

if (run >= 10) {
run = 10;
};

block.onEnterFrame = function() {
    if (Key.isDown(Key.RIGHT)) {
    block._x += run;
    }    
    if (Key.isDown(Key.LEFT)) {
    block._x -= run;
    }    
};


so if I understand this right (I pretty much wrote this myself :hurt:). “block” is the name of the movie clip I want to move. So I make a variable called “run”, which refers to the block’s speed, which starts off pretty slow. Then there are two “if” statements - if “run” is below 10, then it increases by 1. The effect of this should be the block should accelerate, right? The second “if” statement says if “run” is greater than or equal to 10 it should stay at 10, which should cap the speed at 10? I think the “onEnterFrame” event means these “if” statements should repeat every frame.

However, in the .swf file the block moves at a constant rate of 1, never getting any faster. I’m pretty sure I’ve just made an error in the syntax somewhere, any ideas?