A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: KeyboardEvent in class

Threaded View

  1. #2
    Senior Member
    Join Date
    Aug 2006
    Posts
    322
    Actionscript Code:
    package {
        import flash.display.MovieClip;
        import flash.events.KeyboardEvent;

        public class DocumentClass extends MovieClip {
            private var car:Car;
            public function DocumentClass() {
                // constructor code
                car = new Car();
                addChild(car);
                stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
            }
            public function keyPressed(event:KeyboardEvent) {
                if (event.keyCode == 65) {
                    car.x -= 5;
                }
            }
        }
    }

    Actionscript Code:
    package {
        import flash.display.MovieClip;

        public class Car extends MovieClip {
            public function Car() {
                // constructor code
                x = 200;
                y = 300;
            }
        }
    }

    To test this you have to Active the Disable Keyboard Shortcuts from Control tab of the Flash Player.




    marlopax
    Last edited by marlopax; 04-20-2012 at 03:12 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center