在hslide值中添加零

时间:2012-01-20 23:48:41

标签: flex flash-builder

如果值低于10,有人可以帮我弄清楚如何让Flash Builder中的hslide值增加零吗?问题是我需要从hslide获得一个两位数的值,但是如果我输入最小/最大值0-23,如果值低于10,我将只得到一位数。 示例:我想将hslide用作时间幻灯片。如果我选择凌晨4点,我需要的值是04,而不是4.

下面是我的示例代码,hslider1.value和hslider2.value需要两位数。

<fx:Script>
    <![CDATA[

        protected function button1_clickHandler(event:MouseEvent):void
        { navigateToURL(new URLRequest("tel:*23*"+hslider1.value+hslider2.value))  ;
        }       
    ]]>
</fx:Script>

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button y="155" width="269" height="80" label="Button" click="button1_clickHandler(event)"
          color="#FFFFFF" enabled="true" fontSize="24" horizontalCenter="0"/>
<s:HSlider id="hslider1" top="405" width="90%" height="30" dataTipPrecision="0"
           horizontalCenter="0" liveDragging="true" maximum="23" minimum="0" stepSize="1" />

<s:HSlider y="469" width="90%" height="30" id="hslider2" 
           horizontalCenter="1" liveDragging="true" maximum="55" minimum="0" stepSize="5" dataTipPrecision="0"/>


<s:Label x="88" y="291" width="194" height="22" fontSize="24"
         text="{hslider1.value}" textAlign="right"/>
<s:Label x="284" y="291" width="7" height="22" fontSize="24" text=":"/>
<s:Label x="294" y="291" width="194" height="22" fontSize="24" text="{hslider2.value}"/>

任何类型的帮助都将深表感谢! 来自瑞典卡米拉的致敬。

2 个答案:

答案 0 :(得分:0)

嗨,只需将button1_clickhandler函数替换为以下一个..

protected function button1_clickHandler(event:MouseEvent):void
{
    var str1:String = "";
    var str2:String = "";
    if(hslider1.value < 10)
    {
        str1 = "0" + hslider1.value.toString();
    }

    if(hslider2.value < 10)
    {
        str2 = "0" + hslider2.value.toString();
    } 
    navigateToURL(new URLRequest("tel:*23*"+str1+str2))  ;
}

度过美好的一天......

答案 1 :(得分:0)

这是最终代码,以防有人想看到它:

    protected function button1_clickHandler(event:MouseEvent):void
        {
            var str1:String = "";
            var str2:String = "";
            if(hslider1.value < 10)
            {
                str1 = "0" + hslider1.value.toString();
            } else { str1 = hslider1.value.toString();
            } 


            if(hslider2.value < 10)
            {
                str2 = "0" + hslider2.value.toString();
            } else { str2 = hslider2.value.toString();
            } 


            navigateToURL(new URLRequest("tel:*23*" + str1 + str2))  ;
        }