Setting the step size interval on a Spark NumericStepper control in Flex 4

The following example shows how you can set the value interval on a Spark NumericStepper control in Flex 4 by setting the snapInterval property.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.

For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/05/29/setting-the-value-interval-on-a-spark-numericstepper-control-in-flex-4/ -->
<s:Application name="Spark_NumericStepper_snapInterval_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx">
 
    <s:NumericStepper id="numericStepper"
            minimum="-50"
            maximum="50"
            snapInterval="2"
            horizontalCenter="0" verticalCenter="0" />
 
</s:Application>

View source is enabled in the following example.

Due to popular demand, here is the “same” example in a more ActionScript friendly format:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/05/29/setting-the-value-interval-on-a-spark-numericstepper-control-in-flex-4/ -->
<s:Application name="Spark_NumericStepper_snapInterval_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx"
        initialize="init();">
 
    <fx:Script>
        <![CDATA[
            import spark.components.NumericStepper;
 
            private var numericStepper:NumericStepper;
 
            private function init():void {
                numericStepper = new NumericStepper();
                numericStepper.minimum = -50;
                numericStepper.maximum = 50;
                numericStepper.stepSize = 2;
                numericStepper.horizontalCenter = 0;
                numericStepper.verticalCenter = 0;
                addElement(numericStepper);
            }
        ]]>
    </fx:Script>
 
</s:Application>

This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.

5 thoughts on “Setting the step size interval on a Spark NumericStepper control in Flex 4

    1. @Marcus Fritze,

      Correct, thanks. I updated the example code above to reflect the latest API changes (but I haven’t had a chance to create a new SWF or source ZIP, so if you download the source from the view source you’ll still see the old APIs).

      Peter

  1. I have a problem with decimal stepSize, it looks like a problem with the component.

    When set the StepSize or the SnapInterval to something like “0.01”, the stepper goes straight to the maximum value and then it goes completely crazy.

  2. @Tiago

    I had same problem so what i`ve used is this as a solution:

    private function discountValueParse(value:String):Number
    {
    return formatter.parseNumber(value);
    }

    private function discountFormat(value:Number):String
    {
    return formatter.format(value);
    }

    And formatter is defined in declarations tag:

Comments are closed.