Well the problem here is that u don't know what kind of event are
registered and dispatched. Lets say u have a custom class wich has a
method with the name 'doAllThingsPossible' and also has a method with
the name 'click'. This class is registered as an event listener for the
event 'click', how can u know (dynamicly) to what events a certain
object is listening?

In order to do 'removeAllEvents(obj)' the dispatcher needs to keep
record of all objects that registered to an event. To do that u would
need to modify the 'addEventListener' function, and add a property to
the dispatcher class so u are able to save the objects that are
registered as listener, that would be something like this:

var _listeners_obj = new Object();

function addEventListener(event_str, obj)
{
        var _listeners_array = _listeners_obj[event_str];
        if (!_listeners_array.length)
        {
                _listeners_array = _listeners_obj[event_str] = new
Array();
        };
        _listeners_array.push(obj);
        
        return originalAddEventListener(event_str, obj);
};

Now u have an object wich has a key for each event that is listened to,
containing an array with all objects that are listening to that event.
In order to remove all events on a certain object u need to do a loop on
all events, like this"

function removeAllEvents(obj)
{
        for (var i in _listeners_obj)
        {
                var currentEvent_array = _listeners_obj[i];
                var l = currentEvent_array.length;
                while(l--)
                {
                        if (currentEvent_array[l] == obj)
                        {
                                removeEventListener(i, obj);
                        };
                };
        };
};


As u can see this is not very effective. The more listeners u have to a
certain object, the more overhead u will have. I recommend u keep track
of the registered events inside your listening object, or perhaps even
write a class that will function as a default listener. This class would
then contain a function removeAllEvents wich will unregister the events
where needed.


Greetz Erik



-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Scott Barnes
Sent: dinsdag 26 april 2005 8:33
To: [email protected]
Subject: Re: [flexcoders] EventDispatcher Question.


Sorry,

I can locate the listener and can individually unsubscribe events for
that listener, was kind of looking for a forloop style situation where
it can simply iterate over all events a particular object has in its
subscription and simply remove them.



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to