Skip to main content
Participant
May 23, 2016
Question

Animate CC 1119: Access of possibly undefined property KeyCode through a reference with static type flash.events:KeyboardEvent.

  • May 23, 2016
  • 1 reply
  • 643 views

When I play my game (With this script being the only script)

import flash.events.KeyboardEvent;

import flash.events.Event;

stop();

//Character

var charSpeed: Number = 0

var ySpeed: Number = 0

var jumping: Boolean = false

//World

var gravity: Number = 1

//Events

stage.addEventListener(KeyboardEvent.KEY_DOWN, btnPress);

stage.addEventListener(KeyboardEvent.KEY_UP, btnRelease);

stage.addEventListener(Event.ENTER_FRAME, loop);

function btnPress(event: KeyboardEvent): void {

  if (event.KeyCode == Keyboard.LEFT) {

  charSpeed = -5;

  }

  if (event.KeyCode == Keyboard.RIGHT) {

  charSpeed = 5;

  }

  if (event.KeyCode == Keyboard.UP) {

  if (!jumping)

  ySpeed = -14

  jumping = true

  }

}

function btnRelease(event: KeyboardEvent) {

  if (event.KeyCode == Keyboard.LEFT) {

  charSpeed = 0;

  }

  if (event.KeyCode == Keyboard.RIGHT) {

  charSpeed = 0;

  }

}

function loop(e: Event) {

char.x += charSpeed;

if (char.x < -25) {

char.x = -25;

}

if (char.x > 1225) {

char.x = 1225

}

}

I get the following errors:

Scene 1, Layer 'Background&Var', Frame 1, Line 22, Column 12

1119: Access of possibly undefined property KeyCode through a reference with static type flash.events:KeyboardEvent.

Scene 1, Layer 'Background&Var', Frame 1, Line 25, Column 121119: Access of possibly undefined property KeyCode through a reference with static type flash.events:KeyboardEvent.
Scene 1, Layer 'Background&Var', Frame 1, Line 28, Column 121119: Access of possibly undefined property KeyCode through a reference with static type flash.events:KeyboardEvent.
Scene 1, Layer 'Background&Var', Frame 1, Line 36, Column 121119: Access of possibly undefined property KeyCode through a reference with static type flash.events:KeyboardEvent.
Scene 1, Layer 'Background&Var', Frame 1, Line 39, Column 121119: Access of possibly undefined property KeyCode through a reference with static type flash.events:KeyboardEvent.

Do any of you guys have any idea on how to fix this?

Any help would be greatly appreciated.

This topic has been closed for replies.

1 reply

Colin Holgate
Inspiring
May 23, 2016

The "k" in keyCode should be lowercase.