it has no error, it traces down when i pressed and up when I released, but it keeps on walking and attacking even if I released the button whats wrong with the code ?.
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
}
private function enterFrameHandler(e:Event):void
{
// gravitate the player
gravityy += 2;
// move the player
_hero.x += gravityx;
_hero.y += gravityy;
// process collisions
processCollisions();
// scroll the stage
scrollStage();
//movement
if(leftKey)
{
gravityx = -mainSpeed;
_hero.scaleX = 1;
_hero.gotoAndStop("walking");
}
if(rightKey)
{
gravityx = mainSpeed;
_hero.scaleX = -1;
_hero.gotoAndStop("walking");
}
if(aKey)
{
_hero.gotoAndStop("slash");
}
}
private function keyDownHandler(e:KeyboardEvent):void
{
if(e.keyCode == 37)
{
leftKey = true;
trace('down');
}
if(e.keyCode == 39)
{
rightKey = true;
trace('down');
}
if(e.keyCode == 65)
{
aKey = true;
trace('down');
}
}
private function keyUpHandler(e:KeyboardEvent):void
{
if(e.keyCode == 37)
{
leftKey = false;
trace('up');
}
if(e.keyCode == 39)
{
rightKey = false;
trace('up');
}
if(e.keyCode == 65)
{
aKey = false;
trace('up');
}
}
it has no error, it traces down when i pressed and up when I released, but it keeps on walking whats wrong with the code ?.
thanks in advance , !