Had Some Bugs in My Sonic Engine

Hello all. I will ask some question about my Sonic Engine again. I am coding a Sonic Engine(Sonic the Hedgehog). I took the values(for example, acceleration value is *0.046875)*from a Sonic site and use them in my Flash. Whatever, I did at least the jumping, running animation, running etc… but when I tried to code the braking animation, there are occured some bugs in the engine. I tried to fix the bug but I can’t fix it. I am trying to fix it since a few weeks. I think I cut corners if I ask help from forums but I can’t do anything, I tried since days and weeks but I can’t fix. Well, I will tell the bug. First I will give the .fla(I would attach it to the message but it is too big):

http://www.4shared.com/file/1-xTjRXk/SonicTest3.html?

Okay, I will tell the bugs now. First, there is two bugs in the engine(actually I think 3, but I haven’t tried to fix the 3rd one, I focused to first two). First one is, sometimes, when I press the left key or right key when walking or running animation, engine doesn’t obey the command. For example, when I walking to left, I release the left key and I press to the right key. It should add dec value to the speed and turn to the right direction, but it continues to walking left, then after a second, it turn to the right key. I don’t get it why it happens. Second one is tricky one. I don’t know even how to explain that. The point is, when absolute X Speed of Sonic is greater than 4.5, he goes to his braking animation and a Boolean type of variable(sonicBreak) becomes true. But he doesn’t play his braking animation, he just goes to the first frame of braking animation and stop at there. And he continues to go at his X Speed. Actually he slows down in previous fla files that I created, but he doesn’t slow down at this fla. Maybe because of these codes(in if(sonicBreak) line):

if(isDirectionRight)
	spx = 4.4;
if(!isDirectionRight)
	spx = -4.4;

When I delete these lines, it works. But then it plays his braking animation 2-3 times. I want to make him play just once. There are some forms of this bug actually(I mean, it occured often when I tried to change something in that code line), I writed the buggy code purposely at the moment(I changed back the its old state). You would think like “what the…” but I mean, codes were buggy, but then I tried to fix them, I partially fixed them(not really), but I didn’t feel like I learnt the code, if I don’t know why these bugs occured, I would stuck at somewhere again. Then I turned the code into its old state. Also the bug doesn’t occur always. It occurs sometimes. I don’t know why.

Well, sorry for the stupid grammar I used. I was excited and sleepy a little. If you don’t understand anything, ask me about it. Thanks for the help. :egg: