This is a discussion on Event Delegation Model within the Flash Actionscript Programming forums, part of the Web Development category; three participants in the event delegation model: event source: class that broadcasts events event listeners: classes that receive event notifications ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| three participants in the event delegation model: event source: class that broadcasts events event listeners: classes that receive event notifications event object: class that describes the event general structure event occurs (e.g., mouse click, ending of a game, new user joins a chat...etc) event source broadcasts event by invoking an agreed-upon method on all event listeners event object is passed to agreed-upon method as an argument event listeners respond as they see fit (e.g., submit a form, show a game over screen, display a welcome message to the new chat user) the event source the event source includes two classes: the class that broadcasts events (event source is user-defined) EventListenerList: utility to manage event listeners EventListenerList implemenatation EventListenerList resides in "event" pacakge class event.EventListenerList { } EventListenerList also imports the contents of the event package import event.*; array of listener objects stored in instance property, listeners private var listeners:Array; constructor creates empty listeners array: public function EventListenerList () { listeners = new Array(); } addObj() method adds a listener to the listeners array public function addObj (l:EventListener):Boolean { // Search for the specified listener. var len:Number = listeners.length; for (var i = len; --i >= 0; ) { if (listeners[i] == l) { return false; } } // The new listener is not already in the list, so add it. listeners.push(l); return true; } removeObj() method removes a listener from the listeners array public function removeObj (l:EventListener):Boolean { // Search for the specified listener. var len:Number = listeners.length; for (var i:Number = len; --i >= 0; ) { if (listeners[i] == l) { // We found the listener, so remove it. listeners.splice(i, 1); // Quit looking. return true; } } return false; } getListeners() method returns a copy of the listener list, used to broadcast an event public function getListeners ():Array { // Return a copy of the list, not the list itself. return listeners.slice(0); } the event object the event object includes two classes: EventObject, a base class for all event objects an EventObject subclass, whose properties and methods describe a specific event the subclass is user-defined, per event implementation |
| Sponsored Links |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| event.clientX and event.clientY is working in IE but not work in firefox? | senraj | HTML, CSS and Javascript Coding Techniques | 2 | 08-08-2007 05:27 AM |
| what is the threading model used for ASP.Net? | mobilegeek | ASP and ASP.NET Programming | 1 | 07-21-2007 01:48 AM |
| Waterfall model,Spiral model | prasath | Software Testing | 2 | 07-17-2007 03:34 AM |
| OSI model | vadivelanvaidyanathan | Server Management | 0 | 07-15-2007 06:18 PM |
| About W-model | stephen | Software Testing | 1 | 05-16-2007 06:00 AM |