basebuttonrepeater.lzx
<library>
<include href="base/basebutton.lzx"/>
<class name="basebuttonrepeater" extends="basebutton">
<attribute name="_lasttime" value="0
" type="number"/>
<attribute name="stillDownDelegate" value="null
" type="expression"/>
<attribute name="isMouseDown" value="false
" type="boolean"/>
<event name="onmousestilldown"/>
<method name="stillDownEventGenerator" args="ignore">
var now = (new Date()).getTime();
var diff = now - this._lasttime;
this._lasttime = now;
if (this.isMouseDown) {
var next;
if (diff > 600) {
next = 500;
} else {
next = 50;
this.onmousestilldown.sendEvent();
}
lz.Timer.resetTimer( this.stillDownDelegate, next );
}
</method>
<handler name="onmousedown">
this._lasttime = (new Date()).getTime();
this.isMouseDown = true;
if (! this.stillDownDelegate) {
this.stillDownDelegate = new LzDelegate( this, "stillDownEventGenerator" );
}
lz.Timer.addTimer( this.stillDownDelegate, 500 );
</handler>
<handler name="onmouseup">
this.isMouseDown = false;
lz.Timer.removeTimer( this.stillDownDelegate );
</handler>
<doc>
<tag name="shortdesc"><text>a basebutton that sends an event if the mouse is held down.</text></tag>
<text>
<p>This class is a simple extension of
<classname>basebutton</classname>. If the user holds the mouse button
down over the button (for more than a half second), then an event
<event>onmousestilldown</event> will be sent. The
<event>onmousestilldown</event> event will continue to be sent every
50 milliseconds until the mouse button is released.</p>
</text>
</doc>
</class>
</library>
Cross References
Includes
Classes