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

Undefined property keyCode! Please help! Can't find what's wrong!

New Here ,
Sep 01, 2015 Sep 01, 2015

So I'm doing this coding for a college project and I've been repeating retyping the code for 3 times and the same problems still appear!

Here's the code

function keyDownHandler(Event:KeyboardEvent):void

  {

  if(event.keyCode == 38)

  {

  SpeedVert -= .2;

  avatar_mc.gotoAndStop("up")

  }

  else if(event.keyCode == 37)

  {

  SpeedHor -= 1;

  avatar_mc.gotoAndStop("left")

  }

  else if(event.keyCode == 39)

  {

  SpeedHor += 1;

  avatar_mc.gotoAndStop("right")

  }

The Problem

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

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

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

The problem is the keyCode! I can't figure aout what's wrong!

Thank for anyone who's helping!

TOPICS
ActionScript
786
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

correct answers 1 Correct answer

LEGEND , Sep 01, 2015 Sep 01, 2015

In your function definition line you use "Event" (wrong) while the code within the function uses "event" (better).  Fix that for starters.  Also, because the messages all have "MouseEvent" identified in them, I have to wonder if the event listener you have assigned is not specified as a KeyboardEvent listener

Translate
LEGEND ,
Sep 01, 2015 Sep 01, 2015

In your function definition line you use "Event" (wrong) while the code within the function uses "event" (better).  Fix that for starters.  Also, because the messages all have "MouseEvent" identified in them, I have to wonder if the event listener you have assigned is not specified as a KeyboardEvent listener

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
New Here ,
Sep 01, 2015 Sep 01, 2015

When I change the Event to event it works! Thanks! and It appear a new problem, mind if I copy all of the code? It have 120 line codes..

the problem is

1084 Syntax error: expecting right paren before rightbrace

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 ,
Sep 01, 2015 Sep 01, 2015

You're welcome.  You can show all that code if you like, but if it is a problem with a misplaced or missing parenthesis you might want to spend some time trying to find it yourself before giving in and asking someone else to.

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
New Here ,
Sep 01, 2015 Sep 01, 2015

Okay! It works now!

I'm making a landing game? but it seems it can't land it's just passing the landing area..

Full Code:

import flash.events.MouseEvent;

import flash.events.KeyboardEvent;

import flash.events.Event;

var SpeedVert:Number = 0;

var SpeedHor:Number = 0;

go_btn.addEventListener(MouseEvent.MOUSE_OVER, alphaOn);

function alphaOn(event:MouseEvent):void

{

  go_btn.buttonMode = true;

  go_btn.alpha = .8;

}

go_btn.addEventListener(MouseEvent.MOUSE_OUT, alphaOff);

function alphaOff(event:MouseEvent):void

{

  go_btn.buttonMode = false;

  go_btn.alpha = 1;

}

go_btn.addEventListener(MouseEvent.CLICK, startGame);

function startGame(event:MouseEvent):void

{

  go_btn.visible = false;

  avatar_mc.x = -18;

  avatar_mc.y = -38;

  platform_mc.landpoint_mc.y = -24;

  platform_mc.landpoint_mc.visible = true;

  status_txt.text = "";

  avatar_mc.addEventListener(Event.ENTER_FRAME, gravityShip);

  stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);

  stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);

  function gravityShip(event:Event):void

  {

  avatar_mc.y +=  SpeedVert;

  SpeedVert +=  .04;

  avatar_mc.x +=  SpeedHor;

  alt_txt.text = String(Math.floor(platform_mc.landpoint_mc.y - avatar_mc.y) + 344);

  vert_txt.text = String(Math.floor(SpeedVert));

  horiz_txt.text = String(Math.floor(SpeedHor));

  if (SpeedVert>3)

  {

  status_txt.text = "Alert Speed to Fast";

  platform_mc.landpoint_mc.y = 800;

  }

  else

  {

  platform_mc.landpoint_mc.y = 14;

  status_txt.text = "";

  }

  if (avatar_mc.x1.hitTestObject(platform_mc.landpoint_mc))

  {

  trace("Landed");

  SpeedVert = 0;

  SpeedHor = 0;

  status_txt.text = "CONGRATULATION!!";

  gamestatus_txt.text = "Perfect Landing";

  go_btn.visible = true;

  avatar_mc.addEventListener(Event.ENTER_FRAME, gravityShip);

  stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);

  stage.removeEventListener(KeyboardEvent.KEY_UP, keyUpHandler);

  }

  else if (avatar_mc.x1.hitTestObject(crash_area))

  {

  trace("buuuu");

  SpeedVert = 0;

  SpeedHor = 0;

  status_txt.text = "Game Over";

  go_btn.visible = true;

  avatar_mc.addEventListener(Event.ENTER_FRAME, gravityShip);

  stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);

  stage.removeEventListener(KeyboardEvent.KEY_UP, keyUpHandler);

  }

  if (avatar_mc.x > stage.stageWidth)

  {

  avatar_mc.x = 1;

  }

  else if (avatar_mc.x<0)

  {

  avatar_mc.x = 546;

  }

  }

  avatar_mc.addEventListener(Event.ENTER_FRAME, gravityShip);

  function keyDownHandler(event:KeyboardEvent):void

  {

  if (event.keyCode == 38)

  {

  SpeedVert -=  .2;

  avatar_mc.gotoAndStop("up");

  }

  else if (event.keyCode == 37)

  {

  SpeedHor -=  1;

  avatar_mc.gotoAndStop("left");

  }

  else if (event.keyCode == 39)

  {

  SpeedHor +=  1;

  avatar_mc.gotoAndStop("right");

  }

  }

  function keyUpHandler(event:KeyboardEvent):void

  {

  avatar_mc.gotoAndStop("normal");

  }

  stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);

  stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);

}

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 ,
Sep 01, 2015 Sep 01, 2015

Which section of the code you show is relevant to the landing that is giving you a problem? 

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
New Here ,
Sep 01, 2015 Sep 01, 2015

Nevermind I just got it!

Thanks for your help!

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 ,
Sep 01, 2015 Sep 01, 2015
LATEST

You're welcome

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