Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
May 23, 2016 May 23, 2016

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.

TOPICS
ActionScript
624
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 23, 2016 May 23, 2016
LATEST

The "k" in keyCode should be lowercase.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines