Flash handles listening for events in the following way:

adding a listenersomeObject.addEventListener(type, listener)
handling the event with the listenerfunction methodName(event:EventClass):void {// commands to handle event}
removing a listenersomeObject.removeEventListener(type, listener);
The naming convention that is often used for handler or event listener method is:

on + ObjectType + EventType

Flash offers a number of different events through the flash.events package. The packages we will be focusing on this week include:

flash.events.MouseEvent
MouseEvent.CLICK
MouseEvent.DOUBLE_CLICK
MouseEvent.ROLL_OVER
MouseEvent.ROLL_OUT
MouseEvent.MOUSE_DOWN
MouseEvent.MOUSE_UP
flash.events.KeyboardEvent
KeyboardEvent.KEY_DOWN
KeyboardEvent.KEY_UP
flash.events.Events
Event.ENTER_FRAME
Sometimes, you may want to render something immediately after the event occurs. You may do so with the method:

event.updateAfterEvent();

Without doing so, rendering will occur when the next frame plays, which could result in a drawing that is not as smooth.

Some events are associated with default actions that may be prevented. One such event is TextEvent.TEXT_INPUT. By calling the following method, you can prevent the default action of this event, which is to put a character in a text field for a given keyboard press.

event.preventDefault();

For some other references on Event Listeners in AS 3.0, you may find the following helpful:

tutorial by Kyle Brekke
Adobe tutorial (covers some more advanced topics with event model)
download: week 7 samples

update: week 6 solution

Homework:

The Following Reading is optional review. I would encourage you to look over them if you have had trouble synthesizing some of the material thus far:
Cookbook (chapters review what we have covered thus far)
Essential Actionscript 3.0 (more advanced for those who want to dig deeper)
Mid-term assignment:
Create a drawing application
has mouse interactivity
has keyboard interactivity
incorporate previous concepts as appropriate
conditionals
arrays
loops
drawing api
display objects
filters
blend modes
tween
try to be original
Be prepared to present your midterm in class after spring break.

Advertisements