PDA

View Full Version : Using the LzTimer Service


antun
03-11-2003, 04:26 PM
LzTimer is used to set an event to happen after a specified period of time.
Remember that LzTimer is a <i>service</i>, which means you don't just instantiate it like a class.

Say we have a dog that comes when called...


<canvas>
<view name="dog" resource="doggie.png" clickable="true" x="300"
y="15">
<method event="onclick">
this.hereBoy();
</method>
<method name="hereBoy">
this.animate( 'x', 20, 1000, false );
</method>
</view>
</canvas>


... and that dog is really a bit slow, and he doesn't come immediately when called, but it takes him a second or two to react. (In other words we want the hereBoy() method to get called a second or two after the click). We need to do two things:-

Set up a delegate that calls the hereBoy() method.
Add a timer to call that delegate after 1.5 seconds.

The delegate is just a reference point for the method. The LzTimer service must be used with a delegate; you can't just name a method:


<canvas>
<view name="dog" resource="doggie.png" clickable="true"
x="300" y="15">
<method event="onclick">
this.hereDel = new LzDelegate ( this, 'hereBoy' );
LzTimer.addTimer ( this.hereDel, 1500 );
</method>
<method name="hereBoy">
this.animate( 'x', 20, 1000, false );
</method>
</view>
</canvas>


Enjoy!