(re)read the tutorial on widgets.. you'r defining your eventlistener
incorrectly.
it should be a static property of the widget constructor.

cya,

Pascal Bestebroer
[EMAIL PROTECTED]
http://www.dynamic-core.net

> -----Oorspronkelijk bericht-----
> Van: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]Namens John Vilburn
> Verzonden: vrijdag 2 maart 2001 17:32
> Aan: [EMAIL PROTECTED]
> Onderwerp: [Dynapi-Help] Eventlistener firing on all instances of widget
> simultaneously
>
>
> I am writing a widget which creates a horizontal tree. It is based on the
> label widget and recursively creates copies of itself to the depth
> specified. The problem I am having is that the eventlistener seems to fire
> on all copies at the same time. When I mouse over one of the labels, they
> all act as though they have been moused over. Here is the code:
>
> /*
>     Tree Class
>
>     ParentLayer is a DynLayer
>     depth is the depth of the tree
>     RegionRect is the x,y,w,h of the remaining region to draw the tree in
> */
>
> function Tree(ParentLayer,depth,RegionRect)
> {
>  this.Label = Label;
>  this.Label();
>  this.setText('Sample text');
>  this.ParentLayer = ParentLayer;
>  this.TopNode = null;
>  this.BottomNode = null;
>  this.setSize(100,20);
>  this.TopNodeRect = new Array();
>  this.BottomNodeRect = new Array();
>  this.setDepth(depth,RegionRect);
>  this.setBgColor('#c0c0c0');
>  this.setWrap(false);
>  this.setSelectable(false);
>  var listener = new EventListener(this);
>   listener.onmouseover=function(event)
>   {
>    event.getTarget().setText('Mouse Over');
>    window.status = 'Last Event: onmouseover';
>   }
>   listener.onmouseout=function(event)
>   {
>    event.getTarget().setText('Normal');
>    window.status = 'Last Event: onmouseout';
>   }
>   listener.onclick=function(event)
>   {
>    event.getTarget().setText('Click');
>    window.status = 'Last Event: onrtmouseup';
>   }
>   listener.ondblclick=function(event)
>   {
>    event.getTarget().setText('Double Click');
>    window.status = 'Last Event: ondblclick';
>   }
>
>  this.addEventListener(listener);
>  this.ParentLayer.addChild(this);
> }
>
> Tree.prototype = new Label();
>
> Tree.prototype.setDepth = function(newDepth,RegionRect)
> {
>     this.depth = newDepth;
>     this.setRects(RegionRect);
>     if ( this.TopNode == null && this.depth > 1 )
>     {
>         this.TopNode = new
> Tree(this.ParentLayer,this.depth-1,this.TopNodeRect);
>         this.BottomNode = new
> Tree(this.ParentLayer,this.depth-1,this.BottomNodeRect);
>     }
>     if ( this.TopNode != null )
>     {
>         if (this.depth>1)
>         {
>             this.TopNode.setDepth(this.depth-1,this.TopNodeRect);
>             this.BottomNode.setDepth(this.depth-1,this.BottomNodeRect);
>         }
>         else
>         {
>             this.TopNode.setDepth(0,this.TopNodeRect);
>             this.BottomNode.setDepth(0,this.BottomNodeRect);
>         }
>     }
>     if (this.depth>0)
>     {
>      this.setVisible(true);
>     }
>     else
>     {
>         this.setVisible(false);
>     }
> }
>
> Tree.prototype.setRects = function(RegionRect)
> {
>  this.RegionRect = RegionRect;
>
>  var TreeHeight = (this.RegionRect.h - this.getHeight())/2;
>
>  // Move the Label to the correct location
>  this.moveTo(this.RegionRect.x,this.RegionRect.y + TreeHeight);
>
>  if ( this.depth > 1 )
>  {
>   var GapWidth = (RegionRect.w - this.getWidth()*this.depth)/this.depth-1;
>
>   // Set the Rects for this object
>   this.TopNodeRect.x = this.RegionRect.x + this.getWidth() + GapWidth;
>   this.TopNodeRect.y = this.RegionRect.y;
>   this.TopNodeRect.w = this.RegionRect.w - this.getWidth() - GapWidth;
>   this.TopNodeRect.h = TreeHeight
>   this.BottomNodeRect.x = this.TopNodeRect.x;
>   this.BottomNodeRect.y = this.RegionRect.y + this.TopNodeRect.h +
> this.getHeight();
>   this.BottomNodeRect.w = this.TopNodeRect.w;
>   this.BottomNodeRect.h = TreeHeight;
>  }
> }
>
>
>
>
> _______________________________________________
> Dynapi-Help mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/dynapi-help
>


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

Reply via email to