WEB Flex and Actionscript people... why the fuck wont this Number Validator work?

Discussion in 'OT Technology' started by brds, Mar 31, 2010.

  1. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,646
    Likes Received:
    15
    Location:
    Atlanta
    User selects their birthday from a calendar module... clicks a button, and then receives an alert telling them whether they're old enough or not (15 = min age).

    I can get the age calculations stored into an int var (and have it display on the screen) but for some reason, the number validator isn't being called even though it's set up right (or so i think)...

    Here's the code:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application  xmlns:mx="[URL]http://www.adobe.com/2006/mxml[/URL]"  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>
     
  2. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,646
    Likes Received:
    15
    Location:
    Atlanta
    Shit, nobody?

    I showed it to the teacher and he pretty much said that he couldn't see anything wrong with it either and to have fun fixing it by 6 o'clock tonight.

    I might just scrap the calendar part of it and just have the user enter their bday into text boxes.
     
  3. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,923
    Likes Received:
    11
    Location:
    Los Angeles
    :rofl: Awesome professor you have there. :bigthumb:
     
  4. TrenT

    TrenT OT Supporter

    Joined:
    Aug 27, 2002
    Messages:
    10,556
    Likes Received:
    32
    Location:
    NYC
    The logic behind setting the age is off:

    age = int(now.fullYear) - int(date.getFullYear());

    I was born in Dec. 1983, and by the logic above I am (2010 - 1983) I am 27. But I'm not 27 until December.
     
  5. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,646
    Likes Received:
    15
    Location:
    Atlanta
    Yeah i know, but that's not what i was worried about at the time. I later went back and did some month/date logic.
     
  6. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,646
    Likes Received:
    15
    Location:
    Atlanta

    Ya, he's from Ireland too... hard as shit to understand him.
     
  7. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,646
    Likes Received:
    15
    Location:
    Atlanta
    Oh, btw, i figured out a workaround
     

Share This Page