我是flex的新手,我的问题是如何使用" reset"重置mx hslider值。按钮。 这是一个示例脚本:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.events.SliderEvent;
private var txtvalue:int = 0;
protected function Focal_changeHandler(event:SliderEvent):void
{
txtvalue = Focal.value;
if(txtvalue == 0)
Slider_txt.text = "Low";
if(txtvalue == 1)
Slider_txt.text = "Middle";
if(txtvalue == 2)
Slider_txt.text = "High";
}
]]>
</fx:Script>
<mx:HSlider id="Focal" x="476" y="345" maximum="2" minimum="0" value="0" buttonMode="true" enabled="true" snapInterval="1" tickInterval="1" allowTrackClick="true" liveDragging="true" change="Focal_changeHandler(event)"/>
<s:Label id="Slider_txt" x="472" y="319" text= "Low"/>
<s:Button x="476" y="459" label="Reset" id="Res_btn"/>
</s:Application>
答案 0 :(得分:0)
通常你可以做
<s:Button x="476" y="459" label="Reset" id="Res_btn" click="{Focal.value = 0}"/>
但是既然你需要更新文本,最好自己做一个方法:
<s:Button x="476" y="459" label="Reset" id="Res_btn" click="onResetClick()"/>
并在您的代码部分中:
protected function Focal_changeHandler(event:SliderEvent):void
{
updateSliderText();
}
private function onResetClick():void
{
Focal.value = 0;
updateSliderText();
}
private function updateSliderText():void
{
txtvalue = Focal.value;
if (txtvalue == 0)
Slider_txt.text = "Low";
if (txtvalue == 1)
Slider_txt.text = "Middle";
if (txtvalue == 2)
Slider_txt.text = "High";
}