Thanks Alex,
I was able to get this working. I was already using a subclass of
numericStepper. Here is the code if anyone needs to use it:
package classes
{
import flash.events.Event;
import mx.controls.NumericStepper;
import mx.controls.TextInput;
import mx.core.mx_internal;
import mx.formatters.NumberFormatter;
use namespace mx_internal;
public class NumericStepperFormatted extends NumericStepper
{
public function NumericStepperFormatted()
{
super();
addEventListener(Event.CHANGE, handleChange);
}
private function handleChange(e:Event=null):void
{
var nf:NumberFormatter = new NumberFormatter();
nf.precision = 2;
nf.useThousandsSeparator = false;
var txt:TextInput = mx_internal::inputField;
txt.restrict = "[0-9\.]";
var formatted:String = nf.format( Number(txt.text) );
//add a leading 0 for values that are missing a leading 0
if ( formatted.indexOf(".") == 0 )
formatted = "0" + formatted;
txt.text = formatted;
}
override protected function commitProperties():void
{
super.commitProperties();
//since commit properties is the only method that
//calls setValue without dispatching the change
//event, we need to make sure we update the value
//here too
handleChange();
}
}
}
Paul.
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Alex Harui
Sent: Thursday, 26 June 2008 2:37 PM
To: [email protected]
Subject: RE: [flexcoders] Restrict NumericStepper to only numeric characters
I can't think of a supported way to do it, but you can subclass, get the
mx_internal inputField, and change its .restrict property
_____
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Paul Kukiel
Sent: Wednesday, June 25, 2008 7:53 PM
To: [email protected]
Subject: [flexcoders] Restrict NumericStepper to only numeric characters
Anyone know a simple way or a prebuilt adaption of NumericStepper that
restricts Restrict NumericStepper to only numeric characters only. I need
to stop the user inputting commas.
Paul.