I have a function which finds out what button a user pressed using events, and uses the event.key property. However, in the parameter of the function, if i assign it a type Event, the compiler complains that
Property 'key' does not exist on type 'Event'.
Here is my code.
function getDirection(e:Event):void{
let directionCode:number = e.key;
// code going on here
}
Why isnt the key property recognised on type event.
keyCode. Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes.
Note: The which property is deprecated. Use the key property instead. The which property returns the Unicode character code of the key that triggered the onkeypress event, or the Unicode key code of the key that triggered the onkeydown or onkeyup event.
Because Event
does not have that property, KeyboardEvent
is the class you want.
function getDirection(e:KeyboardEvent):void{
let directionCode:number = e.keyCode;
let directionCodeStr:string = e.key;
// code going on here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With