Event Programming Flash
October 2, 2009
Yes, One of the most important part in flash is Event. Flash is an event-driven programming language. Event is very closely related with interaction. Anything happens inside your flash environment either Mouse click, Keyboard press or Load completion is an event while mouse click and others are an interaction that trigger an event.
In order to intercept an Event, First you must register.
Below is Register Listener example :
addEventListener(TypeOfEvent.NameOfEvent,AnyMethod);
and for example if you want flash stage to hear an event then you must add
stage.addEventListener(TypeOfEvent.NameOfEvent,AnyMethod);
TypeOfEvent => Typically this is the class of an Event Class example MouseEvent.
NameOfEvent => Typically this is kind of constant variable of that class Event you used, for example a MouseEvent Class has a variable CLICK as its event type.
AnyMethod => function you would like to execute when an event occured.
If you want flash stage to hear a mouse click event then it will be.
stage.addEventListener(MouseEvent.CLICK,testClick);
function testClick(e:MouseEvent):void{
trace(“It works dude !”);
}
Don’t forgot that “e” from “e:MouseEvent” is an event object. You can also try few things like who trigger me with e.target. Happy Coding and hope you enjoy.