|
-
You need to detect both key up and down press. Try something like below.
var rightClick:Boolean = false;
var leftClick:Boolean = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN, CatcherMove);
stage.addEventListener(KeyboardEvent.KEY_UP, CatcherNoMove);
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
function CatcherMove(e:MouseEvent):void{
switch(e.keyCode){
case Keyboard.LEFT: leftClick = true; break;
case Keyboard.RIGHT: rightClick = true; break;
}
}
function CatcherNoMove(e:MouseEvent):void{
switch(e.keyCode){
case Keyboard.LEFT: leftClick = false; break;
case Keyboard.RIGHT: rightClick = false; break;
}
}
function enterFrameHandler(e:Event):void{
if(rightClick && catcher.x >= 0) catcher.x -=8;
if(leftClick && catcher.x < 600) catcher.x +=8;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|