Be a Supporter!

Keyboard event problem

  • 123 Views
  • 2 Replies
New Topic Respond to this Topic
stickman8190
stickman8190
  • Member since: Mar. 7, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Keyboard event problem 2014-05-01 12:07:33 Reply

public function Level(){
			addEventListener(Event.ENTER_FRAME, loop);
			addEventListener(Event.ADDED_TO_STAGE, onAdded);
			spd=5;
		}
		private function onAdded(event:Event) {
            stage.addEventListener(KeyboardEvent.KEY_DOWN,keyIsDown);
        }

        private function keyIsDown(event:KeyboardEvent) {
            if(event.keyCode == Keyboard.RIGHT) {
                 player_mc += spd;
            }
        }

I'm using a ActionScript 3 Class File and trying to make a simple keyboard movement but the error keeps popping up
1120: Access of undefined property Keyboard.
(I've never used keyboard movements on a as3 class file)


also click Here to view my profile at jiggmin.com

BBS Signature
MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to Keyboard event problem 2014-05-01 13:22:42 Reply

At 5/1/14 12:07 PM, stickman8190 wrote: I'm using a ActionScript 3 Class File and trying to make a simple keyboard movement but the error keeps popping up
1120: Access of undefined property Keyboard.
(I've never used keyboard movements on a as3 class file)

You have to import the class, the same way that you imported KeyboardEvent.

import flash.ui.Keyboard;
stickman8190
stickman8190
  • Member since: Mar. 7, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Keyboard event problem 2014-05-01 14:52:10 Reply

Thanks, it worked


also click Here to view my profile at jiggmin.com

BBS Signature