2011-09-12

FLASH CS3 - Action Script part 5 Keyboard Event (basic)

In previous, I type about Mouse Event. Now I will explain the Keyboard event. the keyboard event same as Mouse Event, with a few (little) difference.

The first you should do for keyboard event is to make sure the focus

stage.focus = this;

unlike mouse that can be clicked to movie clip or an object. Keyboard event for whole stage/movie. to short, let's try this code. The code basicly simple since we not using complex first.. Unlike before, the code will send trace.. So the result isn't able to see offline (outside the Flash programing).


package {
    import flash.display.Sprite;
    import flash.events.KeyboardEvent;
    
    public class ExampleApplication extends Sprite {
        public function ExampleApplication(  ) {
            stage.focus = this;
            addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
        }//function
        
        private function onKeyDown(event:KeyboardEvent):void {
            trace("key down: " + event.charCode);
        }//function
    }//class
}

Since the explaination is simple and same as another tutorial!! I will skip it and begin next tutorial

2 komentar:

Cobray mengatakan...

gambar2mu blas ga nyambung ama artikelnya!

Gustav mengatakan...

biar ada yg komen.. dan biar bs cuci mata dikit.. hehehe