Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Keyboard Function

New Here ,
Aug 14, 2013 Aug 14, 2013

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

TOPICS
ActionScript
507
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 14, 2013 Aug 14, 2013

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);

...
Translate
LEGEND ,
Aug 14, 2013 Aug 14, 2013
LATEST

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);

      }
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines