2 Replies Latest reply on Apr 1, 2010 12:11 PM by Gus187

    Why wont this number validator work?  (Small program - need help)

    brds

      I need to use the number validator for a school project.  I have to have the user select their birthday from a calendar.  After selection of their birthday, the user will click the validate button.  Once the button is clicked, the validator should verify if the age is above 15.

       

      For some reason, the number validator isn't working on the click of the button.  Here's the code i've come up with... any help would be appreciated:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top" horizontalAlign="center" backgroundGradientColors="[0x000000,0x323232]" paddingTop="0" viewSourceURL="srcview/index.html">
         
          <mx:Script>
              <![CDATA[
                  import mx.controls.Text;
                  import mx.controls.Alert;
                 
                  [Bindable] public var minAge:Number = 15;
                  [Bindable] public var age:int;
                 
                  public function displayDate(date:Date):void
                  {
                      if (date == null)
                          selection.text = "Date selected: ";
                      else
                          selection.text = "Date selected: " + (date.getMonth()+1).toString() +
                          '/' + date.getDate() + '/' + date.getFullYear().toString();
                     
                      var now:Date = new Date();
                      age = int(now.fullYear) - int(date.getFullYear());
                      if ((date.getMonth()) >= now.month)
                      {
                          if ((date.getMonth() == now.month) && (date.getDate() > now.date))
                              age--;
                      }
                  }
                 
                  public function showAlert(result:Boolean):void
                  {
                      if (result)
                          Alert.show('You have successfully validated your birthday');
                      else
                          Alert.show('Sorry, you are not old enough');
                  }
             
              ]]>
          </mx:Script>
         
          <mx:NumberValidator source="{age}" property="text" minValue="{minAge}" domain="int" trigger="{vButton}" triggerEvent="click" valid="showAlert(true);" invalid="showAlert(false);" />
          <mx:Panel title="Select Your Birthday" width="600" color="0xffffff" paddingTop="10" borderAlpha="0.15" height="240" layout="horizontal" horizontalGap="15" paddingLeft="10" paddingRight="10" paddingBottom="0" horizontalScrollPolicy="off" verticalScrollPolicy="off">
              <mx:VBox>
                  <mx:DateChooser id="birthday" yearNavigationEnabled="true"  height="145"  
                    change="displayDate(DateChooser(event.target).selectedDate)" color="0x000000"/>
                  <mx:Label id="selection" color="0x323232" text="Date selected:"/>
              </mx:VBox>
              <mx:Canvas width="369" height="179">
                  <mx:Button id="vButton" label="Check Birthday" labelPlacement="left" color="#000000" />
                  <mx:Label id="showage" y="160" text="{age}" color="#000000"/>
              </mx:Canvas>
          </mx:Panel>
      </mx:Application>