O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Event handling

Event handling in AS3 is pretty simple; it basically works by registering listeners to an event.

To do so, we will call the addEventListener function on the object we want to listen to the event on. We will have to pass the name of the event we want to listen to (this is done by passing a String, these strings are stored as statics inside classes in the flash.events package) and a function to handle the event.

The following is an example:

public static function main(): Void { flash.Lib.current.stage.addEventListener (flash.events.KeyboardEvent.KEY_DOWN, keyDown); } private static function keyDown(args : flash.events.KeyboardEvent) { trace(args.keyCode); switch(args.keyCode) { case flash.ui.Keyboard.LEFT: //Left trace("Left"); horizontalSpeed ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required