Search code examples
actionscript-3flashscene

Using QWER keys to jump to a specific scene in AS3


TLDR: I need code in action script 3 which will let users press keys like QWER to jump to a specific scene.

So what I'm doing is creating and interactive comic within flash, and to be blunt I didn't know any AS3 code before this and still pretty much know none.

So I'm going to need some help on this one and I think it is worth mentioning that I am using sound in this project.

what I need to know is how to use letter keys (eg. QWER) to act as shorts cuts to jump to specific scenes. What I have so far which is working is this and another version which uses a mouse click instead.

stop(); ( 1 ) 


stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler);


function fl_KeyboardDownHandler(event:KeyboardEvent):void {



          gotoAndPlay(currentFrame+1);

}

and of course all this does is advance the frame, which I do need for some sections of dialogue but that's the basis I've been trying to get it to work.

I do know that q = 81, w = 87, e = 69 and r = 82.

Besides that I've got nothing and I need some help real bad.


Solution

  • You need to check which key has been pressed, you can do it like this:

    function fl_KeyboardDownHandler(event:KeyboardEvent):void {
     if(event.keyCode == Keyboard.Q){
         //do what you need to do when Q was pressed
     }else if(event.keyCode == Keyboard.W){
         //same for W
     }
    
     ...etc
    }