PDA

View Full Version : how calculate datefield in flex


jumpzz
02-11-2009, 07:08 AM
i doing program Pregnancy
by choose date from datefield

when click submit button result day + 278 will show in state2

+++ How can I insert the code Action script for that

For example code below :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="450" height="600" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#C85907, #F0C66D]" horizontalAlign="left"
>
<mx:states>
<mx:State name="result">
<mx:RemoveChild target="{textarea1}"/>
<mx:RemoveChild target="{datefield1}"/>
<mx:RemoveChild target="{button3}"/>
<mx:RemoveChild target="{label1}"/>
<mx:AddChild relativeTo="{canvas1}" position="lastChild">
<mx:Label x="175.5" y="151" text="dd/mm/yy" fontSize="14" id="label6"/>
</mx:AddChild>
<mx:AddChild relativeTo="{canvas1}" position="lastChild">
<mx:Label x="39" y="151" text="วันคลอด&gt;&gt;&gt;" fontWeight="bold" fontSize="18" id="label5"/>
</mx:AddChild>
</mx:State>
</mx:states>


<mx:Fade duration="2000" id="fade" alphaFrom="0.0" alphaTo="1.0" target="{canvas1}"/>
<mx:Canvas left="10" right="10" top="10" bottom="10" borderStyle="solid" cornerRadius="5" id="canvas1" backgroundColor="#FFFFFF" addedEffect="fade">
<mx:Canvas x="5" y="10" width="396" height="53" backgroundColor="#C04F18" borderStyle="solid" cornerRadius="5" addedEffect="wipeDown" id="img">
<mx:Label x="28.5" y="10" text=" Pregnancy due date calculator" fontFamily="Arial" fontSize="24" fontWeight="bold" color="#FFFFFF" id="label3"/>
</mx:Canvas>
<mx:Label x="52" y="363" text="DATE" fontSize="12" fontWeight="bold" id="label1"/>
<mx:Button x="221" y="357" label="SUBMIT" id="button3" width="73" height="33" fillAlphas="[1.0, 1.0]" fillColors="[#0775BA, #9BD2F5]" color="#000202" click="this.gotocal();"/>
<mx:Label x="21" y="87" text="การคำนวนวันคลอด" fontWeight="bold" fontSize="15" color="#A64F09" fontFamily="Times New Roman" id="label4"/>
<mx:TextArea x="7.75" y="130" width="412.5" height="174" fontSize="12" id="textarea1">
<mx:text><![CDATA[information


]]></mx:text>
</mx:TextArea>
<mx:DateField x="103" y="363" id="datefield1"/>
</mx:Canvas>



<mx:Script>
<![CDATA[
private function gotocal():void{
this.currentState = 'result';
}

]]>
</mx:Script>




<mx:RadioButtonGroup id="mastergroup"/>
</mx:Application>


thanks for all comment :)

Sekhar
02-11-2009, 11:00 PM
Get the date from the string, add the days, and convert it back to string. Below is an example:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
private function calculate(df:DateField):void {
var d:Date = DateField.stringToDate(df.text, df.formatString);

d.date += 278;
df.text = DateField.dateToString(d, df.formatString);
}
]]>
</mx:Script>
<mx:DateField id="dateField" x="10" y="10"/>
<mx:Button click="calculate(dateField);" label="Calculate" x="108" y="10"/>
</mx:Application>