Skip to main content
ChrisFrost
Known Participant
June 15, 2022
Question

Animate Project - Keyboard functions

  • June 15, 2022
  • 1 reply
  • 96 views

Hi everyone,

 

I wonder if someone could help me.  I'm making a website using Adobe Animate with the goal of making it look like a video game.  Most of what I want to do I've figured out, but I'm wondering if someone could help me with a finer detail that's escaped me.  At the beginning of the website/game, a button will appear on the screen saying "Press X to continue".  What I want visitors to be able to do is either of the following;

 

- Upon mouse click of the button, proceed to frame X and stop.

- Upon pressing X on the keyboard, proceed to frame X and stop.

 

Does anyone know how this is achievable please?  Many thanks to all who respond!

 

Chris

    This topic has been closed for replies.

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    June 16, 2022

    Hi.

     

    You could write something like this:

    var root = this;
    
    function startFromPointer()
    {
    	root.gotoAndStop(1);
    }
    
    function startFromKeyboard(e)
    {
    	if (e.key === "x")
    	{
    		window.removeEventListener("keydown", startFromKeyboard);
    		root.gotoAndStop(1);
    	}
    }
    
    root.stop();
    root.pressToStartButton.on("click", startFromPointer, null, true);
    window.addEventListener("keydown", startFromKeyboard);

     

    I hope it helps.

     

    Regards,

    JC