Copy link to clipboard
Copied
So I designed this code for arrow down
var to=0
stage.addEventListener(KeyboardEvent.KEY_UP, fl_KeyboardDownHandler_2);
function fl_KeyboardDownHandler_2(event:KeyboardEvent):void
{
to=1 ; gotoAndPlay(6)
}
My question, How do I modify this code so I can gain input from Alphabet. Because I tried
var to=0
stage.addEventListener(KeyboardEvent.KEY_A, fl_KeyboardDownHandler_2);
function fl_KeyboardDownHandler_2(event:KeyboardEvent):void
{
to=1 ; gotoAndPlay(6)
}
But It Doesn't Works
If you look up the KeyboardEvent class you can see the list of constants that it supports. KEY_A (et al) are not.
What you need to do is check the character code of the key that was pressed to determine if action is to be taken.
stage.addEventListener(KeyboardEvent.KEY_UP, checkKey);
function checkKey(evt:KeyboardEvent):void {
trace(evt.charCode) // use this to find the codes - comment out normally
if(evt.charCode == 97){ // for the letter A
to=1 ;
gotoAndPlay(6);
...Copy link to clipboard
Copied
If you look up the KeyboardEvent class you can see the list of constants that it supports. KEY_A (et al) are not.
What you need to do is check the character code of the key that was pressed to determine if action is to be taken.
stage.addEventListener(KeyboardEvent.KEY_UP, checkKey);
function checkKey(evt:KeyboardEvent):void {
trace(evt.charCode) // use this to find the codes - comment out normally
if(evt.charCode == 97){ // for the letter A
to=1 ;
gotoAndPlay(6);
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now