<multistatebutton>

a button with multiple states, such as a toggle button

JavaScript: multistatebutton

Extends Basebutton

A multistatebutton is an extension of the basebutton class to address the more general class of buttons that can have multiple states, and where each state has it own mouseup, mouseover, and mousedown images. Like the basebutton class, the construction of a multistatebutton starts with a multiframe resource.

The example below create a play/pause button, using the following resources:

With a multistatebutton, the following must be specified explicitly:

statenum
the initial state of a button
statelength
the number of frames (of a multiframe resource) used for a single button state - NOTE: all states must be the same length
maxstate
the total number of states of the button - 1 (since states are counted starting from 0).
Example 1. File "multistatebutton-resources.lzx"
<library>
  <!-- first create the multi-frame resource and give it a name -->
  <resource name="mybutton_rsrc">
     <!--  State: 0 -->
     <!-- first  frame of state 1 = mouseup   image of the button -->
     <frame src="images/multistatebutton/state0-mouseup.jpg"/>
     <!-- second frame of state 1 = mouseover image of the button -->
     <frame src="images/multistatebutton/state0-mouseover.jpg"/>
     <!-- third  frame of state 1 = mousedown image of the button -->
     <frame src="images/multistatebutton/state0-mousedown.jpg"/>

     <!--  State: 1 -->
     <!-- first  frame of state 2 = mouseup image of the button -->
     <frame src="images/multistatebutton/state1-mouseup.jpg"/>
     <!-- second frame of state 2 = mouseover image of the button -->
     <frame src="images/multistatebutton/state1-mouseover.jpg"/>
     <!-- third  frame of state 2 = mousedown image of the button -->
     <frame src="images/multistatebutton/state1-mousedown.jpg"/>
  </resource>
</library>
Example 2. Assigning resources to a button
<canvas height="60">
  <include href="multistatebutton-resources.lzx"/>

  <!-- Second, assign the resource to a basebutton tag -->
  <multistatebutton name="myButton" resource="mybutton_rsrc"
                    statenum="0" statelength="3" maxstate="1"/>
</canvas>

Now, the multistatebutton will stay in state "0" until you switch states. This can be accomplished by calling myButton.setStateNum(number).

Example 3. Switching button states
<canvas height="60">
  <include href="multistatebutton-resources.lzx"/>
  
  <multistatebutton name="myButton" resource="mybutton_rsrc"
                    statenum="0" statelength="3" maxstate="1"
                    onclick="this.toggle()">
     <method name="toggle">
        if (this.statenum == 0) this.setStateNum(1)
        else this.setStateNum(0)
     </method>
  </multistatebutton>
</canvas>
Attributes
Name Usage Type (Tag) Type (JS) Default Category
maxstate Tag & JS number Number 0 setter
 

the largest number allowed for the value of statenum, default: 0


statelength Tag & JS number Number 3 setter
 

the number of frames in a state, default: 3


statenum Tag & JS number Number 0 setter
 

the current state, default: 0



Attributes inherited from Basebutton

disabledResourceNumber, downResourceNumber, maxframes, normalResourceNumber, onresourceviewcount, overResourceNumber, reference, resourceviewcount, respondtomouseout

Attributes inherited from Basecomponent

doesenter, enabled, hasdefault, isdefault, style, styleable, text

Attributes inherited from Node

class, classroot, cloneManager, datapath, id, ignoreAttribute, ignoreplacement, immediateparent, initstage, name, nodeLevel, onconstruct, oninit, parent, placement, subnodes

Attributes inherited from View

aaactive, aadescription, aaname, aasilent, aatabindex, align, bgcolor, clickable, clickregion, clip, cursor, defaultplacement, fgcolor, focusable, focustrap, font, fontsize, fontstyle, frame, framesloadratio, hassetheight, hassetwidth, height, layout, loadratio, mask, onblur, onclick, ondata, ondblclick, onfocus, onkeydown, onkeyup, onmousedown, onmouseout, onmouseover, onmouseup, onselect, opacity, options, pixellock, play, resource, resourceheight, resourcewidth, rotation, selectiontype, showhandcursor, source, stretches, subviews, totalframes, unstretchedheight, unstretchedwidth, valign, visible, width, x, xoffset, y, yoffset


Methods

setStateLength()
multistatebutton.setStateLength(s)

setter for the statelength attribute

Parameters
Name Type Desc
s None


setStateNum()
multistatebutton.setStateNum(s)

setter for the statenum attribute

Parameters
Name Type Desc
s None


Methods inherited from basebutton

doSpaceDown, doSpaceUp, setResourceViewCount, showDown, showOver, showUp

Methods inherited from basecomponent

doEnterDown, doEnterUp, setStyle, setTint, updateDefault

Methods inherited from LzNode

animate, applyConstraint, applyData, childOf, completeInstantiation, createChildren, dataBindAttribute, destroy, determinePlacement, getAttribute, getOption, getUID, lookupSourceLocator, searchImmediateSubnodes, searchSubnodes, setAttribute, setDatapath, setID, setName, setOption

Methods inherited from LzView

addProxyPolicy, addSubview, bringToFront, construct, containsPt, getAttributeRelative, getBounds, getColor, getColorTransform, getContextMenu, getCurrentTime, getDepthList, getHeight, getID3, getMouse, getPan, getTotalTime, getVolume, getWidth, init, measureHeight, measureWidth, play, releaseLayouts, removeProxyPolicy, searchParents, searchSubviews, seek, sendBehind, sendInFrontOf, sendToBack, setAAActive, setAADescription, setAAName, setAASilent, setAATabIndex, setAlign, setAttributeRelative, setBGColor, setClickable, setColor, setColorTransform, setContextMenu, setCursor, setHeight, setLayout, setOpacity, setPan, setPlay, setResource, setResourceNumber, setRotation, setShowHandCursor, setSource, setValign, setVisible, setVolume, setWidth, setX, setY, shouldYieldFocus, stop, stretchResource, unload, updateResourceSize


Events

Events inherited from LzNode

onconstruct, ondata, oninit

Events inherited from LzView

onaddsubresource, onaddsubview, onblur, onclick, ondblclick, onerror, onfocus, onframe, onheight, onlastframe, onload, onmousedown, onmousedragin, onmousedragout, onmouseout, onmouseover, onmouseup, onmouseupoutside, onopacity, onplay, onremovesubview, onstop, ontimeout, onwidth, onx, ony