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 http://www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see http://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.


{ 2 comments… read them below or add one }
it seems that valueInterval was renamed to snapInterval in the final release?!
@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