Search code examples
actionscript-3eventskeyboardflash-cs4

How to detect if the delete key was pressed in Actionscript 3?


How do I determine if the delete key was pressed using actionscript?

addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

...

function onKeyUp(event:KeyboardEvent):void
{
    trace(event.keyCode);
}

The above code yields no value when delete, backspace, enter, and other command keys are pressed. However, arrow keys do yield values.


Solution

  • this.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);
    ....
    
    function onKeyPressed(event:KeyboardEvent):void
    {
       if (event.keyCode==Keyboard.DELETE) {
           .....
           }
    
    }
    

    it's workin nice... But if you test movie from Flash, it will not work, so export to swf and test....