0

我需要在我的 SLabel text=" " 中放置什么来显示我的 if 语句定义的内容?到目前为止,这是我的代码:

<?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;
        protected function ValueSlider_changeHandler(event:SliderEvent):void
    {
        ValueLabel.text = String(ValueSlider.value);
            if(String(ValueSlider.value) == "0")
            ValueLabel.text = "150";
            if(String(ValueSlider.value) == "1")
            ValueLabel.text = "333";
            if(String(ValueSlider.value) == "2")
            ValueLabel.text = "543";
            if(String(ValueSlider.value) == "3")
            ValueLabel.text = "9342";
    }
    ]]>
</fx:Script>
<s:Panel x="199" y="141" width="250" height="200">
    <s:HSlider id="ValueSlider" x="78" y="69" maximum="3" minimum="0" stepSize="1" value="1"/>
    <s:Label id="ValueLabel" x="109" y="38" text= "{ValueLabel.text}"/>
</s:Panel>

4

1 回答 1

0

导入 mx.events.SliderEvent;

<s:HSlider id="ValueSlider" x="78" y="69" maximum="3" minimum="0" stepSize="1" value="1"/>

s:HSlider spark 没有SliderEvent

s:HSlider应该绑定到 mx:HSlider。mx:HSlider 没有stepSize所以删除它。
为了使“ValueSlider_changeHandler(event)”生效,必须设置为:

change="ValueSlider_changeHandler(event)"

完整的线路:

    <mx:HSlider id="ValueSlider" x="78" y="69" maximum="3" minimum="0" value="1" change="ValueSlider_changeHandler(event)"/>

现在它应该看起来像:

     <fx:Script>
        <![CDATA[
            import mx.events.SliderEvent;
            private var slvalue:int = 0;
            protected function ValueSlider_changeHandler(event:SliderEvent):void
            {
                slvalue = ValueSlider.value;
                if(slvalue == 0)
                    ValueLabel.text = "150";
                if(slvalue == 1)
                    ValueLabel.text = "333";
                if(slvalue == 2)
                    ValueLabel.text = "543";
                if(slvalue == 3)
                    ValueLabel.text = "9342";
            }
        ]]>
    </fx:Script>
    <s:Panel x="199" y="141" width="250" height="200">
        <mx:HSlider id="ValueSlider" x="78" y="69" maximum="3" minimum="0" value="1" change="ValueSlider_changeHandler(event)"/>
        <s:Label id="ValueLabel" x="109" y="38" text= "{ValueLabel.text}"/>
    </s:Panel>

你不能像这样测试它:

ValueLabel.text = String(ValueSlider.value);
            if(String(ValueSlider.value) == "0")
            ValueLabel.text = "150";

ValueLabel.text = "150"立即被下一个事件覆盖!!!

将其存储在局部变量中!以上:slvalue

于 2012-11-04T23:34:25.980 回答