Skip navigation
Matt201496
Currently Being Moderated

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

Jul 7, 2012 10:39 PM

Tags: #error #keyboard #event #1119
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")

        }

   

    }

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points