View Full Version : Events based on a views position
cmcginnis
04-14-2004, 01:01 PM
I'm animating a view from one point to another and I would like to fire off an event when it reaches a certain point.
For example:
<view name="box" width="10" height="10" bgcolor="red">
<animator attribute="x" from="10" to="100"
repeat="infinity" duration="1500"/>
</view>
When this view reaches x="53" I would like to fire off an event. It seems like it is possible, but I'm not sure how to do it.
Thanks for the help.
antun
04-14-2004, 03:17 PM
One way is to use the onx event of the view, and run a method that checks the value:
<canvas debug="true">
<view name="box" width="10" height="10" bgcolor="red">
<animator attribute="x" from="10" to="100"
repeat="Infinity" duration="1500"/>
<method event="onx">
if ( this.x >= 53 ) {
this.myevent.sendEvent();
}
</method>
</view>
<view>
<method event="oninit">
// Note: Something must be listening for the event in order
// for it to be sent.
var foo = new LzDelegate( this, "notify", box, "myevent" );
</method>
<method name="notify">
Debug.write( "myevent got sent" );
</method>
</view>
</canvas>
Note this shows you how to actually send a custom event (called myevent). You might just be OK with calling something from the onx method.
You could also set up a delegate that listened out for the onx event and did the same kind of thing. It's a bit less clear to understand that approach, but let me know if you need to see it.
-Antun
cmcginnis
04-14-2004, 03:20 PM
This is perfect. Thanks!
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.