IT Community - Software Programming, Web Development and Technical Support

Event Delegation Model

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 ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Flash Actionscript Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-15-2007, 04:23 AM
nssukumar nssukumar is offline
D-Web Sr.Programmer
 
Join Date: Feb 2007
Posts: 155
nssukumar is on a distinguished road
Default Event Delegation Model

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 10:46 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0