Using the classroot property

The classroot property of the View class refers to the root node of a class instance. It is often used from a deeply nested view or method to reference a view near the root of the class. For example, consider the code in Listing 12.6.

Listing 12.6. Using the classroot keyword
<canvas>
    <class name="root">
        <simplelayout axis="x"/>
        <view height="100" width="100">
            <button x="20" y="20" text="Red">
                <handler name="onclick">
                    classroot.setAttribute("bgcolor", "0xff0000");
                </handler>
            </button>
        </view>
        <view height="100" width="100">
            <button x="20" y="20" text="Blue">
                <handler name="onclick">
                    classroot.setAttribute("bgcolor", "0x0000ff");
                </handler>
            </button>
        </view>

    </class>

    <root bgcolor="#cecece" height="400" width="400"/>
</canvas>

You can use the following URL to compile the code in Listing 12.6.

http://localhost:8080/lps-4.0.x/app12/classrootTest1.lzx

The result is shown in Figure 12.5.

Figure 12.5. Using classroot


The buttons can be used to change the background color of the root instance. Clicking the Red button changes it to red and clicking the Blue button changes it to blue.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset