PDA

View Full Version : on custom event


3.14
04-29-2004, 02:26 PM
i would like to create a class with an 'onMyEvent' attribute, so that the code in this attribute is executed when the instance of this class emits an event with type 'MyEvent' : how can i do that?
thx

vfunshteyn
05-03-2004, 01:20 PM
Here's a modified example from the reference page for LzEvent, that does what you're asking about:

<canvas height="40" >
<simplelayout/>
<button name="eventSender"
onmouseover="this.customevent.sendEvent()"
onmouseout="this.customevent.sendEvent()"/>
<view bgcolor="red" width="20" height="20" oninit="this.setupDelegate()">
<method name="setupDelegate">
this.del = new LzDelegate( this, "oncustomevent" );
this.del.register( eventSender , "customevent" );
</method>

<method name="oncustomevent">
this.setAttribute( 'x' , this.x + 10 );
</method>
</view>
</canvas>


It is currently not possible to declare a custom event handler as an attribute - you have to split it into its own method, as in the example above.