Copy link to clipboard
Copied
Scene 1, Layer 'Layer 1', Frame 1, Line 5 | 1119: Access of possibly undefined property LEFT through a reference with static type Class. |
Scene 1, Layer 'Layer 1', Frame 1, Line 6 | 1119: Access of possibly undefined property DOWN through a reference with static type Class. |
Scene 1, Layer 'Layer 1', Frame 1, Line 7 | 1119: Access of possibly undefined property UP through a reference with static type Class. |
Scene 1, Layer 'Layer 1', Frame 1, Line 8 | 1119: 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")
}
}
Your listeners need to specify KeyboardEvents, and UP,DOWN,LEFT,RIGHT are not KeyboardEvents, they are Keyboard keyCodes. Use either KEY_DOWN or KEY_UP in place of all of them in the listeners.
Copy link to clipboard
Copied
Your listeners need to specify KeyboardEvents, and UP,DOWN,LEFT,RIGHT are not KeyboardEvents, they are Keyboard keyCodes. Use either KEY_DOWN or KEY_UP in place of all of them in the listeners.
Copy link to clipboard
Copied
Thanks that worked.
Copy link to clipboard
Copied
You're welcome
Copy link to clipboard
Copied
You also need to add breaks in each of your cases.
There are a few of syntax errors so hopefully you didn't copy and paste your actual code.