Wednesday, March 01, 2006

assigning an event multiple methods; setAttribute not setText

This is a little piece of Laszlo code that demos a couple of things I keep forgetting: 1) how to assign multiple methods to an event and 2) how to set button text programmatically (button does not have a setText method, and this.text = "bla" does not work).


<canvas height="100%" width="100%" debug="true">
<view>
   <button name="mybutton" onclick="writethat(); shrink();">
     <method name="writethat">
       this.setAttribute("text", "that");
     </method>
     <method name="shrink">
       this.setAttribute("width", this.width-1);
     </method>
   </button>
</view>
</canvas>

The following code will work to assign multiple methods as well:

<button name="mybutton" onclick="writethat(); shrink()">

Or you can do it without the space, even:

<button name="mybutton" onclick="writethat();shrink()">

It's adding quotes which gets problematic. This is the right way:

<button name="mybutton" onclick="writethat();shrink();Debug.write(&quot;hello&quot;)">

Escaping quotes with a backslash like this does not work because we are in XML-land:

<button name="mybutton" onclick="writethat();shrink();Debug.write(\"hello\")">

If you do the latter, you get this completely unhelpful compiler error: "Whitespace required before attributes. cannot be resolved or is not a field" and also 'Element type "button" must be followed by either attribute specifications, ">" or "/>"'.

0 Comments:

Post a Comment

<< Home