FLASH AS3: Help me determine why this code isn't accepting keystrokes
Output is:
[object Stage]
listening?
listening! (ONLY IN DEBUGGING MODE)
65 (ONLY IN DEBUGGING MODE)
...
import flash.events.KeyboardEvent
import flash.events.Event
import flash.ui.Keyboard;
import flash.display.Stage
...
public function Start()
{
trace(stage);
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
trace("listening?");
this.addEventListener(Event.ENTER_FRAME, DoFrame);
}
private function KeyPressed(eventx:KeyboardEvent):void
{
trace("listening!");
LastGuess=eventx.keyCode;
trace(LastGuess);
}
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$2 Answers
Also try creating a sprite or other object, adding that to the stage, specifying position and dimensions of the object, and listening to events on that object.
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$this.stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
creates a listener on this to stage for Event.KEY_DOWN. but stage should never dispatch Event.KEY_DOWN.
Another words... the eventListener declaration has to happen within the object you want to listen for the event, the above code tells this to listen for an event from stage, it doesn't tell stage to listen for an event.
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$