Button

A Button object represents a clickable button. A button is also used to raise an event, so that you can perform an action upon a click on the button. We will discuss event handling in Chapter 5, “Event Handling.”

The Button class is the template for creating Button objects. This class is a subclass of BaseButton, which in turn is a subclass of BaseComponent. The class hierarchy is shown in Figure 2.11.

Figure 2.11. The hierarchy of the Button class


The attributes of BaseButton and those of Button are listed in Tables 2.7 and 2.8, respectively.

Table 2.7. The attributes of the BaseButton class
NameUsageTypeDefaultAccessibility
disabledResourceNumberTag onlynumber4final
 Description. The resource for the disabled state. Use 0 if the resource has at least four frames and there is no disabled state.
downResourceNumberTag onlynumber3final
 Description. The resource for the mouse down state. Use 0 if the resource has at least three frames and there is no down state.
maxframesTag onlynumber final
 Description. The maximum number of frames to use.
normalResourceNumberTag onlynumber1final
 Description. The resource for the mouse up state, and the initial state of the button.
onresourceviewcountTag and JSboolean read-write
 Description. This event is raised when the value of resourceviewcount changes.
overResourceNumberTag and JSboolean final
 Description. This event is raised when the resourceviewcount changes.
referenceTag onlystring final
 Description. The target of mouse events.
resourceviewcountTag and JSnumber0read-write
 Description. The number of the first subviews that will respond to mouse events by changing the resource’s frame number.
respondtomouseoutTag and JSbooleantrueread-write
 Description. Indicates if this button responds to onmouseout or onmousedragout events.

Table 2.8. The attributes of the Button class
NameUsageTypeDefaultAccessibility
text_padding_xTag and JSnumber11read-write
 Description. The amount of space to add horizontally when resizing button to its text.
text_padding_yTag and JSnumber4read-write
 Description. The amount of space to add vertically when resizing button to its text.
text_xTag and JSnumber read-write
 Description. The x position of the button text. The default is centered.
text_yTag and JSnumber read-write
 Description. The y position of the button text. The default is centered.

The BaseButton class defines the following methods:

doSpaceDown()

Shows the down state. This method only takes effect if the space bar is down.

doSpaceUp()

Shows the up state. This method will only take effect if the space bar is up.

setResourceViewCount(resourceViewCount)

Sets the resourceviewcount attribute.

showDown(sd)

Called when the button’s visible state should appear to be down. The argument sd is not used.

showOver(sd)

Called when the button’s visible state should appear to be raised, to indicate it can be clicked.

showUp(sd)

Called when the button’s visible state should appear to be up.

The following are methods defined in the Button class.

doEnterDown()

Called by the button manager when this button is the default.

doEnterUp()

Called by the button manager when this button is the default.

The buttonTest1.lzx file in Listing 2.9 presents an LZX application that uses a button. The button’s text says, “Click Here.”

Listing 2.9. Using a button
<canvas width="150">
    <button>Click Here</button>
</canvas>

To compile the LZX application, direct your browser here to this URL:

http://localhost:8080/lps-4.0.x/app02/buttonTest1.lzx

Figure 2.12 shows the generated output.

Figure 2.12. Using button


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

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