Skip to main content
March 4, 2011
Answered

Help with possible mouseEvent/Keyboard Event problem

  • March 4, 2011
  • 1 reply
  • 450 views

Hi guys, I am having trouble with a game I am creating right now.  The problem seems to lie on mouse / Keyboard event.

Basically, I have a character that the player can control using the  keyboard arrow keys and it works perfectly fine on its own.  Whenever the game starts,  the player can control the character instantly with the keyboard. Here's the problem now, after I added another page (at frame 1) and created a start game button, those keyboard events  won't start immediately anymore.  The player must click on the stage  again before it works.  Is there any method to solve this?

Right now, here is my Start button page.

var start_btn:Start_btn = new Start_btn;
start_btn.addEventListener (MouseEvent.CLICK, goGame);

function goGame(event:MouseEvent) {
gotoAndStop("game"); //The game's frame
this.removeEventListener(MouseEvent.CLICK,goGame);
}

Here's some code for the actual game part.

stage.addEventListener(KeyboardEvent.KEY_DOWN,keyP  ressed);

function keyPressed (e:KeyboardEvent) :void {
//character movement code...like charcter.x++, x-- etc
}

Thanks in advance

This topic has been closed for replies.
Correct answer Wrataxas

How about trying:

     stage.focus = stage;

in goGame().

1 reply

Wrataxas
WrataxasCorrect answer
Participant
March 8, 2011

How about trying:

     stage.focus = stage;

in goGame().