icontogglebutton.lzx
<library>
<class name="icontogglebutton" extends="basebutton" focusable="true" styleable="true" resourceviewcount="3" doesenter="true" style="$once{custombutton_style}">
<attribute name="iconresource" value="
" type="string"/>
<attribute name="icony" value="null
"/>
<attribute name="statenum" value="0
" setter="setStatenum(statenum)"/>
<stableborderlayout axis="x"/>
<view name="left" resource="custombutton_small_left_rsc"/>
<view name="middle" resource="custombutton_small_middle_rsc" stretches="width"/>
<view name="right" resource="custombutton_small_right_rsc"/>
<view name="icon" resource="${classroot.iconresource}" x="${(parent.width - width)/2}" y="${classroot.icony != null ? classroot.icony : (parent.height - height)/2}"/>
<method name="showOver">
super.showOver();
this.setFrame(2);
</method>
<method name="showUp">
super.showUp();
this.setFrame(1);
</method>
<method name="showDown">
super.showDown();
this.setFrame(3);
</method>
<handler name="onclick">
this.setStatenum(this.statenum ? 0 : 1);
</handler>
<method name="setStatenum" args="s">
this.statenum = s;
if (!this.isinited) {
//catch the case where this.statenum is being initialized during object instantiation
return;
}
this.icon.setAttribute('frame', s+1);
</method>
<method name="setFrame" args="f">
this.left.setAttribute('frame', f);
this.middle.setAttribute('frame', f);
this.right.setAttribute('frame', f);
</method>
<method name="_applystyle" args="s">
if (s != null) {
this.setTint(this.left, s.basecolor);
this.setTint(this.middle, s.basecolor);
this.setTint(this.right, s.basecolor);
}
</method>
</class>
</library>