I have the following code in a state (much like that in the developer
documentation):
<attribute name="mx" value="${parent.getMouse('x')}"/>
<method event="onmx">
You'll probably want to use LzIdle.onidle events, then check where the
mouse is:
<attribute name="mx" value="0"/>
<method name="checkMouse" event="onidle" reference="LzIdle">
setAttribute( 'mx', parent.getMouse( 'x' ) );
</method>
<method event="onmx">
// ...
</method>
When I try it the "onmx" event method is called repeatedly even when
the mouse is not moving. Am I doing something wrong?
Constraints are a subtle business. They watch the value of attributes to
see if they change. For example, ${ parent.width - width } watches the
view's width attribute and its parents width attribute. When someone
calls setAttribute on one of these two attributes, the constraint is
recalculated and the attribute is updated.
Having said that, I don't know why your constraint was firing all the
time. I would think it would fire once, since it doesn't depend on any
attribute - the string 'x' is a constant. Apparently it fires multiple
times. I wouldn't rely on this behavior.
A neat trick to avoid calling methods when the value has been updated
(but remains the same as it was before) uses a setter:
<attribute name="mx" value="0" setter="setMx( mx )"/>
<method name="setMx" args="m">
if ( (typeof( this['mx'] ) != 'number') || (m != mx) ) {
this.mx = m;
if ( !this['onmx'] ) new LzEvent( this, 'onmx' );
onmx.sendEvent( m );
}
</method>
Dan Stowell
Software Engineer
Laszlo Studios
_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user