Skip to main content
Participant
August 17, 2022
Answered

Switching to a next frame with a specific button.

  • August 17, 2022
  • 1 reply
  • 417 views

Hi, I was trying to figure out how to switch to a next frame by pressing a specific button on your keyboard, In this case I would like the button to be "3" and switch to the frame 41. I got it only to work with any key but couldn't make it work with "3" or any other specific key.

 

This is the code that only worked for me:

 

stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler_5);

function fl_KeyboardDownHandler_5(event:KeyboardEvent):void
{

gotoAndStop(30);

}

 

I'm new to this so if anyone is willing to help i'm grateful. Thanks!

 

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    Hi.

     

    You could write something like this:

    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;
    
    function fl_KeyboardDownHandler_5(event:KeyboardEvent):void
    {
    	if (event.keyCode == Keyboard.NUMBER_3)
    		gotoAndStop(41);
    }
    
    stop();
    stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler_5);

     

    I hope it helps.

     

    Regards,

    JC

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    August 17, 2022

    Hi.

     

    You could write something like this:

    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;
    
    function fl_KeyboardDownHandler_5(event:KeyboardEvent):void
    {
    	if (event.keyCode == Keyboard.NUMBER_3)
    		gotoAndStop(41);
    }
    
    stop();
    stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler_5);

     

    I hope it helps.

     

    Regards,

    JC

    Participant
    August 17, 2022

    It's perfect! Thanks so much 🙂

    JoãoCésar17023019
    Community Expert
    Community Expert
    August 17, 2022

    You're welcome!