4 Replies Latest reply: Jul 8, 2012 4:39 PM by Ned Murphy RSS

    Error 1119: Access of a possibly undefined property with a keyboard event

    Matt201496
      Scene 1, Layer 'Layer 1', Frame 1, Line 51119: Access of possibly undefined property LEFT through a reference with static type Class.
      Scene 1, Layer 'Layer 1', Frame 1, Line 61119: Access of possibly undefined property DOWN through a reference with static type Class.
      Scene 1, Layer 'Layer 1', Frame 1, Line 71119: Access of possibly undefined property UP through a reference with static type Class.
      Scene 1, Layer 'Layer 1', Frame 1, Line 81119: Access of possibly undefined property RIGHT through a reference with static type Class.

       

      I think have to set Keyboard.Event.LEFT,UP,DOWN,RIGHT to public but not sure how.

      import flash.events.KeyboardEvent;

       

      stage.addEventListener(KeyboardEvent.LEFT, characterMove);

      stage.addEventListener(KeyboardEvent.DOWN, characterMove); \\\ Event listeners for keyboard up left etc.

      stage.addEventListener(KeyboardEvent.UP, characterMove);

      stage.addEventListener(KeyboardEvent.RIGHT, characterMove);

       

      new public; function characterMove(evt:KeyboardEvent):void {     \\ function to move person

          switch (evt.keyCode){

                  case Keyboard.LEFT:

                      person.x -= 20;

                     

                  case Keyboard.RIGHT:

                      person.x += 20;

                     

                  case Keyboard.DOWN:

                      person.y -= 20;

                     

                  case Keyboard.UP :

                      person.y += 20;

                     

                  default:

                      trace("Keyboard Event Error")

              }

         

          }