0

即使我已经在类中进一步定义了该函数,我在已加星标的行上的以下代码中收到访问未定义属性的错误:

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():
    }
  }
}

编辑:修复大写错误后弹出新错误(谢谢杰森)。谁能帮我这个?

4

1 回答 1

1

Private必须是小写才能成为访问修饰符关键字private

如:

private static var initialized:Boolean = false;

作为大写Private,编译器假定您正在引用命名空间“Private”,例如:

package
{
    import flash.utils.flash_proxy;
    import mx.core.mx_internal;

    use namespace arcane;

    public dynamic class X
    {
        flash_proxy var prop1:Boolean;

        mx_internal var prop2:Boolean;

        arcane var prop3:Boolean;
    }
}
于 2012-05-31T02:57:10.200 回答