At 2001-08-17 18:10, you wrote:
>Bugs item #425789, was opened at 2001-05-20 19:21
>You can respond by visiting: 
>http://sourceforge.net/tracker/?func=detail&atid=105757&aid=425789&group_id=5757
>
>Category: DynAPI 2 Events
>Group: None
>Status: Open
>Resolution: None
>Priority: 5
>Submitted By: a.joannou (conan1)
>Assigned to: Jordi Ministral (dodoron)
>Summary: Events Fire On All Objects (same subcls)
>
>Initial Comment:
>        On objects made from other objects which in turn are made from the DynLayer 
>(e.g. 
>scrollPane),  eventListeners placed on one object, fire on ALL of them as outlined in 
>the following 
>example. Why is this? Is there a solution?
>        This problem is apparent on any objects created in the same way (e.g. if I 
>create an 
>object 'A' based on DynLayer, and then create an object 'B' based on object 'A', the 
>same problem 
>occurs). 
>        This makes programming of complex objects IMPOSSIBLE.
>
>Looking forward to your prompt reply.
>Deli.
[snip]


The problem is the objects share the same eventListener array [in your example it can 
be verified with an alert(scrollpane1.eventListeners === scrollpane2.eventListeners); 
line].

So, how to fix it? I wasn't able to find a nice way to do it so the following kludge 
will do for now...

(Because eventListeners are a rather fundamental aspect of the code it is less of a 
kludge than it really is :-)

In dynlayer.js, make the DynLayer function end with:

        // These aren't used unless listeners.js is included
        this.eventListeners = [];
        this.hasEventListeners = false;
};

and change one line in listeners.js:
DynObject.prototype.addEventListener=function(listener) {
        if(!this.hasEventListeners) { this.eventListeners = []; }       // <- This 
changed
        this.hasEventListeners = true;
        for (var i=0;i<this.eventListeners.length;i++) if 
(this.eventListeners[i]==listener) return;
        this.eventListeners[this.eventListeners.length]=listener;
}

NB: I only made a quick-and-dirty test-case, and I got the desired results with these 
changes. Please check so it doesn't break anything else!

/Lunna


_______________________________________________
Dynapi-Dev mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-dev

Reply via email to