How to determine if the delete key is pressed in ActionScript 3?

How to determine if the delete key is pressed using actionscript?

addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

...

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

The code above does not give a value when the delete, return, enter, and other commands are pressed. However, the arrow keys give values.

+3
source share
4 answers
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);
....

function onKeyPressed(event:KeyboardEvent):void
{
   if (event.keyCode==Keyboard.DELETE) {
       .....
       }

}

it works well ... But if you are testing a movie from Flash, this will not work, so export to swf and test ....

+8
source

Just guessing that you are using the TEXT_INPUT event, this does not work to delete and return. To catch them, you can add an eventListener to the scene and listen KeyboardEvent.

+2

, , , . , , stage. stage , , null. ADDED_TO_STAGE .

+1

, - : Flash Player IDE . , "" > " " , .

+1

Source: https://habr.com/ru/post/1719676/


All Articles