Issue
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.
Solution
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
}
Answered By - Titian Cernicova-Dragomir
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.