Ok, from the start, let's declare the variable just for clarification
var ICanWalkRight = true;
Well, you just started the game, you should be able to walk Right
And let's say this is your code for walking right now, not actual code as you can see
When I press Right
{
Add 2 to MyCharacter._x
}
And when you collide with a wall, you use the
if (MyCharacter.hitTest(Wall))
{
ICanWalkRight = false;
}
So, if you collide with a wall, it will turn the variable to false, now you just need to apply this variable state to the code for walking
When I press Right AND ICanWalkRight == true
{
Add 2 to MyCharacter._x
}
To be honest, that wouldn't work, because you only have one movieclip to test both direction, so you'd also get a ICanWalkLeft = false if you had one, but then you could create invisible symbols inside your character, properly placed into the right or left side to detect proper collisions, like RightDetect
if (MyCharacter.RightDetect.hitTest(Wall))
{
ICanWalkRight = false;
}
And you would still have trouble because you would never be able to walk Right again after colliding, because ICanWalkRight would be false forever, except you did a negating code for it too
if (MyCharacter.hitTest(Wall))
{
ICanWalkRight = false;
}
else
{
ICanWalkRight = true;
}
I made it a little confusing, sorry about that