9 Replies Latest reply on Jul 27, 2011 7:59 AM by jfb00

    Extended component cannot save data

    jfb00 Level 3

      Hi All,

      I am attaching an extended texInput component to allow only numbers and format the number with 2 decimals, also to manage the actual value in different option than text display.

      I can assign the value using text or realValue options.

      At the time of passing data from my extended component thru remote object it doesn't pass the data.

      <mx:method name="addNew" result="addNew_RO_Handler(event)">
                  <mx:arguments>
                      <number_id>{myField.realValue}</number_id>

       

      When I debug, I can see the value:  realValue = 6565 [0x19a5]

      In my method arguments shows as NaN.

      Any ideas?I am sure something simple is missing.

      Thanks

       

      JFB

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:TextInput xmlns:mx="http://www.adobe.com/2006/mxml" textAlign="right" creationComplete="init()" >
          <mx:Script>
              <![CDATA[
                  import mx.controls.listClasses.*;
                  import mx.formatters.NumberFormatter;
                  
                  private var _realValue:Number;
                  private const POSITIVE_COLOR:uint = 0x000000; // Black
                  private const NEGATIVE_COLOR:uint = 0xFF0000; // Red
                  
                  private function init():void
                  {
                      //init code
                      super.restrict = '0-9\.\\-';
                  }
                  
                  private function formatDecimal(val:Number):String
                  {
                      var decimalFormatter: NumberFormatter = new NumberFormatter();
                      decimalFormatter.rounding = 'nearest';
                      decimalFormatter.precision = 2;
                      decimalFormatter.useNegativeSign = false;
                      return decimalFormatter.format(val);
                  }
                  
                  public function set realValue(value:Number):void
                  {
                      //Set real value
                      _realValue = value;
                      
                      // format the number here
                      super.text = formatDecimal(_realValue);
                      dispatchEvent( new Event('realValueChange') ); 
                  }
                  
                  [Bindable(Event='realValueChange')]   
                  public function get realValue():Number
                  {
                      //Return component text real value
                      return _realValue;
                  }
                  
                  override public function set text(value:String):void
                  {
                      _realValue = Number(value);
                      
                      // format the number here
                      super.text = formatDecimal(_realValue);
                  }
                  
                  override protected function focusInHandler(event:FocusEvent):void
                  {
                      //Update component text real value
                      super.text = _realValue.toString();
                  }
                  
                  override protected function focusOutHandler(event:FocusEvent):void
                  {
                      //Check if the source is blank
                      if (event.target.text == '')
                          _realValue = 0;
                      else
                          _realValue = Number(event.target.text);
                      
                      //Update component text value
                      super.text =  formatDecimal(_realValue);
                  }
                  
                  override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
                  {
                      super.updateDisplayList(unscaledWidth, unscaledHeight);
                      
                      // Set the font color red for negative numbers
                      setStyle('color', (_realValue < 0) ? NEGATIVE_COLOR : POSITIVE_COLOR);
                  }
      
              ]]>
          </mx:Script>
      </mx:TextInput>