0 Replies - 873 Views - Last Post: 16 June 2008 - 01:59 AM

#1 RodgerB  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 66
  • View blog
  • Posts: 2,284
  • Joined: 21-September 07

Key Down Event in 3.0

Posted 16 June 2008 - 01:59 AM

Description: 1) Copy and paste the snippet into the actions pane of a frame. 2) Read the comments.Demonstrates asynchronous handling of key presses in ActionScript 3.0. NOTE: This method does not handle multiple key presses. ActionScript 3.0 sucks for this ;).
// Import the flash events. We need to use the KeyboardEvent event.
import flash.events.*;

// Declare the event
stage.addEventListener(KeyboardEvent.KEY_DOWN, key_down);

// The handler for the KEY_DOWN event.
function key_down(e:KeyboardEvent):void 
{
    // do stuff.
    // example of doing stuff.
    if(e.keyCode == 32)
    {
        // if the user presses space, do stuff.
        // you can see a full list of key codes here:
        // http://people.uncw.edu/tompkinsj/112/FlashActionScript/keyCodes.htm
    }
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1