PDA

View Full Version : What's the difference between a method and a handler?


pcawdron
01-18-2007, 03:21 AM
What's the difference between a method and a handler? Why would you use one over the other in any given situation? They appear to be almost identical, which has me scratching my head wondering why there are two different scripting event types.

I came across an old, old, old (not so specky) OpenLaszlo example at...

http://www.xml.com/lpt/a/1677

And it had methods and handlers used interchangeably, so I thought I'd ask the question, why? Take a look at the code from the article and you'll see what I mean...

<text x="10" text="Add a New Contact" fontstyle="bold" bgcolor="#F2F2F2">
<handler name="onclick">
messagetext.setText("");
if(phonelist.visible){phonelist.setVisible(false); }
if(contactallinfo.visible){contactallinfo.setVisib le(false);}
newperson.setVisible(true);
newperson.resetForm();
newperson.title.setAttribute('text','New Contact');
</handler>
</text>

<text x="10" text="List all contacts in the book" fontstyle="bold" bgcolor="#F2F2F2">
<method event="onclick">
messagetext.setText("");
if(newperson.visible){newperson.setVisible(false); }
parent.parent.listAllContacts();
contactallinfo.setVisible(false);
phonelist.setVisible(true);
</method>
</text>

Just curious as to which one I should use in any given situation and why...

caclark
01-18-2007, 04:47 AM
The <method event=""> technique was the original way. To make things more clear and let you declare your intentions, the developers added the <event name=""> + <handler name=""> paradigm.

While you can use them interchangeably, the recommendation is to use the <event> + <handler> technique.

notzippy
01-18-2007, 05:34 AM
Using the <method event=""> technique is now deprecated and should not be used as soon it will not work at all (3.4 release I believe I was told)

Another nice thing you can do with an handler is call a method directly from its method attribute. For example.


<handler name="onattributea" method="commonChange"/>
<handler name="onattributeb" method="commonChange"/>
<method name="commonChange">
Debug.write("attributea or attributeb was changed");
</method>


Also dont forget about the reference attribute which allows you to customize were the event is comming from.

Z

pcawdron
01-18-2007, 12:56 PM
Great explanations.... thanks...