ActionScript 3Working with Events


Events are pieces of data that a program can create, exchange and react upon. The asynchronous event flow is dispatched over display list by Flash engine as a reaction on external events, such as mouse movements or another frame being displayed. Every other event flow and all event processing is synchronous, so if a piece of code has generated an event, all reactions on it are processed before the next line of code is executed, also if there are several listeners of an event, all of them would have run before the next event could be processed.

There are several major events associated with Flash programming. Event.ENTER_FRAME is generated before Flash draws another frame, it signals the entire display list to prepare to be drawn, and can be used as a synchronous timer. MouseEvent.CLICK and its siblings can be used to receive mouse input from the user, and TouchEvent.TOUCH_TAP is an analogue for touch screens. KeyboardEvent.KEY_DOWN and KEY_UP provide means to receive user input from the keyboard, however, their usage in mobile department is almost impossible due to devices having no physical keyboard. Finally, Event.ADDED_TO_STAGE is dispatched once a display object receives access to stage, and is included in the global display list that receives the entirety of events that can bubble up and down the display list.

Most events in Flash are component specific. If you are designing your own component that will use Flash events, use a descendant class and its static String properties to create your component's event set.