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

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

New Here ,
Jul 07, 2012 Jul 07, 2012

Copy link to clipboard

Copied

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")

        }

   

    }

TOPICS
ActionScript

Views

3.8K

Translate

Translate

Report

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 , Jul 07, 2012 Jul 07, 2012

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.

Votes

Translate

Translate
LEGEND ,
Jul 07, 2012 Jul 07, 2012

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.

Votes

Translate

Translate

Report

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 ,
Jul 08, 2012 Jul 08, 2012

Copy link to clipboard

Copied

Thanks that worked.

Votes

Translate

Translate

Report

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 ,
Jul 08, 2012 Jul 08, 2012

Copy link to clipboard

Copied

LATEST

You're welcome

Votes

Translate

Translate

Report

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 ,
Jul 07, 2012 Jul 07, 2012

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.

Votes

Translate

Translate

Report

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