Game, Multiple Animations?

I am making a game much like this one.
http://www.funny-games.biz/wpnfire.html

The thing which i am having problems with is having different animations play for the character. For example if hes running and I have a running animation set up on frame 2 of the character movie clip what happens is when i test it ,it goes back and forth and messes up.

Has anyone had experience in platform games or anything similar?

Heres a snippet of code, from this you should hopefully see whats going wrong.

Enter Frame code

[AS]

    if(moveRight) {
            this.x += Physics.PLAYERSPEED;
            this.gotoAndPlay("walking");
     }

[/AS]

Thanks