I am receiving an error of access of undefined property from the following code on the line which i've starred, even though i have already defined the function further in the class:
package {
import flash.display.Stage;
import flash.events.Event;
import flash.events.KeyboardEvent;
public class Key{
private static var initialized:Boolean = false;
private static var keysDown:Object = new Object();
private function initialize(stage:Stage){
if(!initialized){
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
**stage.addEventListener(Event.DEACTIVATE, clearKeys);**
initialized = true;
}
}
public static function isDown(keyCode:uint):Boolean {
return Boolean(keyCode in keysDown);
}
Private static function keyPressed(event:KeyboardEvent):void {
keysDown[event.keyCode] = true;
}
private static function keyReleased(event:KeyboardEvent):void{
if(event.keyCode in keysDown){
delete keysDown[event.keyCode];
}
}
Private static function clearkeys(event:Event):void{
keysDown = new Object():
}
}
}
EDIT:New error popping up after I have fixed the caps error (Thank you Jason). Can anyone help me with this?