2007.01.28...5:59 am

Access the old value of a numeric stepper in Flex 2

Jump to Comments

Problem:
The numeric stepper and numeric stepper event in Flex 2 do not tell you which button (up or down) was pressed and there is no way to determine what the value was prior to the change that triggered the event.

Solution:
Extend and replace the numeric stepper class with a class that allows you to access the value of the stepper prior to the change. With the prior value you can tell not only what the old value is but also then which direction the stepper was moved

Here is the code:


 package com.ohms.components  {  import mx.controls.NumericStepper;
/*
 NumericStepper class (replacement for mx.controls.NumericStepper)
 by Justin Ohms  (justinohms@gmail.com)
 created 2007-01-27 This extension for the NumericStepper class was created
 to allow an easy way to determine which direction the
 stepper was last moved (up or down) To this end this class adds a single read only property OldValue
 that will return the value of the stepper prior to the last change. */ public class NumericStepper extends mx.controls.NumericStepper {
 public function NumericStepper()
 {
 super();
 } private var _oldvalue:Number = 0; public function get OldValue():Number
 {return this._oldvalue;} override protected function commitProperties():void
 {
 //Prior to the ""proposed value"" being commited,
 // save the current value to the oldvalue property
 this._oldvalue = value;
 super.commitProperties();
 } } }

Leave a Reply