Skip to main content
Participant
Aug 17, 2022 3:55 PM UTC
Answered

Switching to a next frame with a specific button.

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 is closed to new replies. Start a new post to keep the conversation going.
    JoãoCésar17023019
    JoãoCésar17023019Correct answer
    Community Expert
    Aug 17, 2022 4:18 PM UTC

    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

    3 replies

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    Aug 17, 2022 4:18 PM UTC

    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

    Translate
    Participant
    Aug 17, 2022 4:31 PM UTC

    It's perfect! Thanks so much 🙂

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    Aug 17, 2022 4:44 PM UTC

    You're welcome!

    Translate