Skip to main content
juanaldinho
Participating Frequently
September 22, 2014
Question

How do i assign a keyboard function to a buttton created.

  • September 22, 2014
  • 1 reply
  • 644 views

How do i assign a keyboard function to a buttton created. I have a game witch if i press SPACE bar somethiong happens. but i want to crate a button on screen tha if i press it it would be the same as pressing the space bar

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
September 23, 2014

Just assign code to the button that processes the desired code when you click it...

yourButton.onRelease = doSomethingFunction;

function doSomethingFunction(){

    //  whatever...

}

Have the keypress calling that same function

juanaldinho
Participating Frequently
September 23, 2014

thnk you Ned, for your response, im sorry but im new to flash and dont understand, If i have a button that has a instance name of spacebar. how do i program it so that when a press it is like pressing the space bar on the keyboard.

Thank you very much

Ned Murphy
Legend
September 23, 2014

What does pressing the spacebar do?  Whatever that is, just assign the same kind of code for the button.  If the button is named spacebar, then just replace what I called "yourButton" with "spacebar"