Problem with walls

I need some help. I finally made my hero to not walk on the wall. But for some reason when he gets near the wall and tried to walk on the other direction, he kinda stuck. Except if my hero will walk in opposite direction from the direction he used to be.

this is the code for my hero MC:

onClipEvent(load){
moveSpeed = 4;

}
onClipEvent(enterFrame){
if(Key.isDown(Key.UP)){
this.gotoAndStop(1);
char.play();
this._y -= moveSpeed;
}
if(Key.isDown(Key.DOWN)){
this.gotoAndStop(5);
char.play();
this._y += moveSpeed;
}
if(Key.isDown(Key.LEFT)){
this.gotoAndStop(2);
char.play();
this._x -= moveSpeed;
}
if(Key.isDown(Key.RIGHT)){
this.gotoAndStop(4);
char.play();
this._x += moveSpeed;
}
if(this.hitTest(_root.map) && (Key.isDown(Key.RIGHT) ||
Key.isDown(Key.LEFT) || Key.isDown(Key.UP) || Key.isDown(Key.DOWN))){
moveSpeed = 0;

}else {
    moveSpeed = 4;
}

}