-
1. Re: Arrow Movements In Flash CS4
Ned Murphy Sep 13, 2009 4:47 PM (in response to Me2LoveIt2)While I can't say I understand what drives the precedence of events, when you process a key down event, I reckon only the last keydown event holds as the one that gets passed to the function. So what you probably need to do is use these events to establish other controls for the movement, keeping track of when each is active versus not.... here's one possible approach...
var goDown:Boolean = false;
var goUp:Boolean = false;
var goLeft:Boolean = false;
var goRight:Boolean = false;
function hearKeyDown(yourEvent:KeyboardEvent):void{
if (yourEvent.keyCode==Keyboard.RIGHT){ goRight = true; }
if (yourEvent.keyCode==Keyboard.LEFT){ goLeft = true; }
if (yourEvent.keyCode==Keyboard.UP){ goUp = true; }
if (yourEvent.keyCode==Keyboard.DOWN){ goDown = true; }
}function hearKeyUp(yourEvent:KeyboardEvent):void{
if (yourEvent.keyCode==Keyboard.RIGHT){ goRight = false; }
if (yourEvent.keyCode==Keyboard.LEFT){ goLeft = false; }
if (yourEvent.keyCode==Keyboard.UP){ goUp = false; }
if (yourEvent.keyCode==Keyboard.DOWN){ goDown = false; }
}function moveCube(evt:Event):void {
if (goRight){ cube_mc.x+=5 };
if (goLeft){ cube_mc.x-=5 };
if (goUp){ cube_mc.y-=5 };
if (goDown){ cube_mc.y+=5 };
}stage.addEventListener(KeyboardEvent.KEY_DOWN, hearKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, hearKeyUp);
stage.addEventListener(Event.ENTER_FRAME, moveCube);


