Name

multistatebutton — a button with multiple states, such as a toggle button

Synopsis

LZX: multistatebutton
JavaScript: lz.multistatebutton
Type: Class
Access: public
Topic: Components.Base Components
Declared in: lps/components/base/multistatebutton.lzx

Description

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 33. 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 34. 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>

Superclass Chain

node (LzNode) » view (LzView) » basecomponent » basebutton » multistatebutton

Known Subclasses

Details

Properties (5)

frame
<attribute name="frame" value="${this.lastres + (this.statenum * this.statelength)}" />
private var frame;
lastres
<attribute name="lastres" type="number" value="1" />
private var lastres : Number;
maxstate
<attribute name="maxstate" type="number" value="0" />
public var maxstate : Number;
the largest number allowed for the value of statenum, default: 0
statelength
<attribute name="statelength" type="number" value="3" />
public var statelength : Number;
the number of frames in a state, default: 3
statenum
<attribute name="statenum" type="number" value="0" />
public var statenum : Number;
the current state, default: 0

Methods (6)

setStateLength()
<method name="setStateLength" args="s" />
public function setStateLength(s);
setter for the statelength attribute
setStateNum()
<method name="setStateNum" args="s" />
public function setStateNum(s);
setter for the statenum attribute
showDown()
<method name="showDown" args="sd" />
private function showDown(sd);
_showEnabled()
<method name="_showEnabled" />
private function _showEnabled();
showOver()
<method name="showOver" args="sd" />
private function showOver(sd);
showUp()
<method name="showUp" args="sd" />
private function showUp(sd);

Events (2)

onstatelength
<attribute name="onstatelength" />
private event onstatelength;
onstatenum
<attribute name="onstatenum" />
private event onstatenum;

LZX Synopsis

<class name="lz.multistatebutton" extends=" lz.basebutton ">
  <attribute name=" frame " value="${this.lastres + (this.statenum * this.statelength)}" />
  <attribute name=" lastres " type="number" value="1" />
  <attribute name=" maxstate " type="number" value="0" />
  <attribute name=" statelength " type="number" value="3" />
  <attribute name=" statenum " type="number" value="0" />
  <event name=" onstatelength " />
  <event name=" onstatenum " />
  <method name=" setStateLength " args="s" />
  <method name=" setStateNum " args="s" />
  <method name=" showDown " args="sd" />
  <method name=" _showEnabled " />
  <method name=" showOver " args="sd" />
  <method name=" showUp " args="sd" />
</class>

JavaScript Synopsis

public lz.multistatebutton extends  lz.basebutton  {
  private var frame ;
  private var lastres  : Number;
  public var maxstate  : Number;
  public var statelength  : Number;
  public var statenum  : Number;
  prototype private event onstatelength ;
  prototype private event onstatenum ;
  prototype public function setStateLength (s);
  prototype public function setStateNum (s);
  prototype private function showDown (sd);
  prototype private function _showEnabled ();
  prototype private function showOver (sd);
  prototype private function showUp (sd);
}