[Laszlo-dev] I really thought I understood classroot, but I was wrong

John Sundman jsundman at laszlosystems.com
Tue Jan 30 12:06:18 PST 2007


Ben,

Good catch.

jrs

On Jan 30, 2007, at 2:29 PM, Benjamin Shine wrote:

> This example also looks like it relies on implicit this, which is  
> discouraged.
>>>>     <method name="handleclick">
>>>>       Debug.write("this = " + this);
>>>>       Debug.write("classroot= " + this.classroot); // must be  
>>>> this.classroot, not just classroot
>>>>     </method>
>
> On Jan 30, 2007, at 11:14 AM, Max Carlson wrote:
>
>> This has confused me in the past.  The rationale is, you might  
>> want to do 'classroot.classroot' and for this to work, classroot  
>> in the root instance must refer to the parent's classroot.
>>
>> -Max
>>
>> Henry Minsky wrote:
>>> classroot is bound in all the children, but it's not bound in the  
>>> root
>>> instance.
>>> So, you could do
>>> <canvas debug="true">
>>> <class name="myclass">
>>>   <attribute name="button_label" type="text" value="button"/>
>>>   <handler name="onclick">
>>>     this.handleclick()
>>>   </handler>
>>>   <method name="handleclick">
>>>     Debug.write("this = " + this);
>>>   </method>
>>>   <button name="b1" text="${parent.button_label}"
>>> onclick="Debug.write('classroot
>>> = ' + classroot); parent.handleclick()" />
>>> </class>
>>> <class name="another_class" extends="myclass"/>
>>> <myclass id="foo">
>>>   <another_class id="bar" button_label ="another button" y="25">
>>>      <method name="handleclick">
>>>        Debug.write("this = " + this);
>>>      </method>
>>>  </another_class>
>>> </myclass>
>>> </canvas>
>>> On 1/30/07, John Sundman <jsundman at laszlosystems.com> wrote:
>>>>
>>>> Why does clicking on the child button report that classroot is  
>>>> null?
>>>> How do I get it to show a real classroot?
>>>>
>>>> <canvas debug="true">
>>>> <class name="myclass">
>>>>     <attribute name="button_label" type="text" value="button"/>
>>>>     <handler name="onclick">
>>>>       this.handleclick()
>>>>     </handler>
>>>>
>>>>     <method name="handleclick">
>>>>       Debug.write("this = " + this);
>>>>       Debug.write("classroot= " + classroot);
>>>>     </method>
>>>>     <button text="${parent.button_label}"  
>>>> onclick="parent.handleclick
>>>> ()" />
>>>> </class>
>>>>
>>>> <class name="another_class" extends="myclass"/>
>>>>
>>>> <myclass>
>>>>     <another_class button_label ="another button" y="25">
>>>>        <method name="handleclick">
>>>>          Debug.write("this = " + this);
>>>>          Debug.write("another_class classroot= " + classroot);
>>>>        </method>
>>>>    </another_class>
>>>> </myclass>
>>>> </canvas>
>>>>
>>>> Thanks,
>>>>
>>>> jrs
>>>>
>>
>> -- 
>> Regards,
>> Max Carlson
>> OpenLaszlo.org
>
> Benjamin Shine
> Software Engineer, Open Laszlo / Laszlo Systems
> ben at laszlosystems.com
>
>
>



More information about the Laszlo-dev mailing list