3 Replies Latest reply: Dec 5, 2012 4:59 PM by kglad RSS

    Keyboard commands

    mentalcase129 Community Member

      Been helping a friend put together a website with my Actionscript knowledge but he's just asked about another idea that I've never attempted.  How would you go about setting up keyboard commands to navigate the website?  His navigation is pretty simply but he's interested in giving it a bit more of an interactive/gaming feel to it so you can use the arrow keys to move back and forth between sections of the site.  And maybe even another key like space bar or something.

       

      I'm sure it's possible to do such a thing but I don't have a clue where to begin.

        • 1. Re: Keyboard commands
          kglad CommunityMVP

          start with the keyboardevent class:

           

          stage.addEventListener(KeyboardEvent.KEY_DOWN,keydownF);

          function keydownF(e:KeyboardEvent):void{

          trace(e.keyCode);

          // code your navigation here.  using a switch-case statement is an easy way to proceed.

          }

          • 2. Re: Keyboard commands
            mentalcase129 Community Member

            I'm not sure if I know what you mean by "a switch-case statement." Do  you mean just replace "CLICK" with "KEY_DOWN" or something like that?

            • 3. Re: Keyboard commands
              kglad CommunityMVP

              no.  more like:

               

              stage.addEventListener(KeyboardEvent.KEY_DOWN,keydownF);

               

              function keydownF(e:KeyboardEvent):void{

                  switch(e.keyCode){

                      case 37:

                          // back

                          break;

                      case 39:

                          // forward

                          break;

                  }

               

              }