flex calculation problem

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

flex calculation problem

FlexCoders mailing list
Hello Guys, i have a small problem. i have this form where i calculated updated balance based on data already available and data from 2 text inputs. the result is correct but i would like that when someone types in one textinput the balance is computed and then further if someone inputs a figure in the second text input. below is the code i got as of now. It needs improvement.
 

 <?xml version="1.0" encoding="utf-8"?>
 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
 layout="vertical"
 horizontalAlign="center"
 verticalAlign="top">
 
 <mx:Script>
 <![CDATA[
 
 private function calBalance(event:Event):void
 {
 var amt:Number=new Number;
 
 if (Number(amountPaid.text) > Number(currentPaid.text) && Number(manFees.text) > Number(currentFees.text)){
 amt = Number(currentBal.text) - ((Number(amountPaid.text) - Number(currentPaid.text)) + (Number(manFees.text) - Number(currentFees.text)))
 }
 
 balance.text=amt.toFixed(0);
 }
 
 ]]>
 </mx:Script>
 
 <mx:Panel height="400"
  layout="vertical">
 

 <mx:HBox>
 <mx:Label text="Payment:"
  width="113"/>
 <mx:TextInput id="amountPaid" change="calBalance(event)"/>
 <mx:Label text="Management Fees:"/>
 <mx:TextInput id="manFees" change="calBalance(event)"/>
 </mx:HBox>
 

 <mx:HRule width="100%"/>
 <mx:HBox>
 <mx:Label text="Current Balance:"
  width="126"/>
 <mx:Text text="515000"
 id="currentBal"/>
 </mx:HBox>
 <mx:HBox>
 <mx:Label text="Amount Already Paid:"
  width="126"/>
 <mx:Text text="500000"
 id="currentPaid"/>
 </mx:HBox>
 <mx:HBox>
 <mx:Label text="Fees Paid:"
  width="126"/>
 <mx:Text text="0"
 id="currentFees"/>
 </mx:HBox>
 <mx:HBox>
 <mx:Label text="updated Balance:"
  width="126"/>
 <mx:Text id="balance"/>
 </mx:HBox>
 </mx:Panel>
 

 
 </mx:Application>
 

 

Reply | Threaded
Open this post in threaded view
|

Re: flex calculation problem

FlexCoders mailing list
I'm not sure if you are aware, but using a form is a better choice. To answer your question, use a change listener on the text input to achieve what you need.

http://stackoverflow.com/questions/4361638/how-to-campture-the-text-change-event-of-a-text-control-to-call-a-function-in-fl


Sent from my iPhone

> On Apr 15, 2015, at 8:12 AM, [hidden email] [flexcoders] <[hidden email]> wrote:
>
> Hello Guys, i have a small problem. i have this form where i calculated updated balance based on data already available and data from 2 text inputs. the result is correct but i would like that when someone types in one textinput the balance is computed and then further if someone inputs a figure in the second text input. below is the code i got as of now. It needs improvement.
>
>
>
> <?xml version="1.0" encoding="utf-8"?>
>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
>
> layout="vertical"
>
> horizontalAlign="center"
>
> verticalAlign="top">
>
>
>
> <mx:Script>
>
> <![CDATA[
>
>
>
> private function calBalance(event:Event):void
>
> {
>
> var amt:Number=new Number;
>
>
>
> if (Number(amountPaid.text) > Number(currentPaid.text) && Number(manFees.text) > Number(currentFees.text)){
>
> amt = Number(currentBal.text) - ((Number(amountPaid.text) - Number(currentPaid.text)) + (Number(manFees.text) - Number(currentFees.text)))
>
> }
>
>
>
> balance.text=amt.toFixed(0);
>
> }
>
>
>
> ]]>
>
> </mx:Script>
>
>
>
> <mx:Panel height="400"
>
>  layout="vertical">
>
>
>
> <mx:HBox>
>
> <mx:Label text="Payment:"
>
>  width="113"/>
>
> <mx:TextInput id="amountPaid" change="calBalance(event)"/>
>
> <mx:Label text="Management Fees:"/>
>
> <mx:TextInput id="manFees" change="calBalance(event)"/>
>
> </mx:HBox>
>
>
>
> <mx:HRule width="100%"/>
>
> <mx:HBox>
>
> <mx:Label text="Current Balance:"
>
>  width="126"/>
>
> <mx:Text text="515000"
>
> id="currentBal"/>
>
> </mx:HBox>
>
> <mx:HBox>
>
> <mx:Label text="Amount Already Paid:"
>
>  width="126"/>
>
> <mx:Text text="500000"
>
> id="currentPaid"/>
>
> </mx:HBox>
>
> <mx:HBox>
>
> <mx:Label text="Fees Paid:"
>
>  width="126"/>
>
> <mx:Text text="0"
>
> id="currentFees"/>
>
> </mx:HBox>
>
> <mx:HBox>
>
> <mx:Label text="updated Balance:"
>
>  width="126"/>
>
> <mx:Text id="balance"/>
>
> </mx:HBox>
>
> </mx:Panel>
>
>
>
>
> </mx:Application>
>
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: flex calculation problem

FlexCoders mailing list
In reply to this post by FlexCoders mailing list
Actually this is the entire code with 2 scenarios. but needs a liltle tweaking to make it better. by better i mean, the balance starts off getting computed the moment either the amountPaid textinput or manFees textinput is being fed in a figure. thanks

 <?xml version="1.0" encoding="utf-8"?>
 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
 layout="vertical"
 horizontalAlign="center"
 verticalAlign="top">
 
 <mx:Script>
 <![CDATA[
 
 private function calBalance(event:Event):void
 {
 var amt:Number=new Number;
 
 if (Number(amountPaid.text) > Number(currentPaid.text) && Number(manFees.text) > Number(currentFees.text)){
 amt = Number(currentBal.text) - ((Number(amountPaid.text) - Number(currentPaid.text)) + (Number(manFees.text) - Number(currentFees.text)))
 }
 
 if (Number(amountPaid.text) < Number(currentPaid.text) && Number(manFees.text) > Number(currentFees.text)){
 //amt = Number(currentBal.text) + ((Number(currentPaid.text) - Number(amountPaid.text)) + (Number(manFees.text) - Number(currentFees.text)))
 
 amt = (Number(currentBal.text) + (Number(currentPaid.text) - Number(amountPaid.text))) - (Number(manFees.text) - Number(currentFees.text))
 }
 
 balance.text=amt.toFixed(0);
 }
 
 ]]>
 </mx:Script>
 
 <mx:Panel height="400"
  layout="vertical">
 

 <mx:HBox>
 <mx:Label text="Payment:"
  width="113"/>
 <mx:TextInput id="amountPaid" change="calBalance(event)"/>
 <mx:Label text="Management Fees:"/>
 <mx:TextInput id="manFees" change="calBalance(event)"/>
 </mx:HBox>
 

 <mx:HRule width="100%"/>
 <mx:HBox>
 <mx:Label text="Current Balance:"
  width="126"/>
 <mx:Text text="515000"
 id="currentBal"/>
 </mx:HBox>
 <mx:HBox>
 <mx:Label text="Amount Already Paid:"
  width="126"/>
 <mx:Text text="500000"
 id="currentPaid"/>
 </mx:HBox>
 <mx:HBox>
 <mx:Label text="Fees Paid:"
  width="126"/>
 <mx:Text text="0"
 id="currentFees"/>
 </mx:HBox>
 <mx:HBox>
 <mx:Label text="updated Balance:"
  width="126"/>
 <mx:Text id="balance"/>
 </mx:HBox>
 </mx:Panel>
 

 </mx:Application>
   
 
Reply | Threaded
Open this post in threaded view
|

Re: flex calculation problem

FlexCoders mailing list
Any help guys?

Reply | Threaded
Open this post in threaded view
|

Re: flex calculation problem

FlexCoders mailing list
In reply to this post by FlexCoders mailing list
Hello, thanks for the response. i am already using a change listener on the text input but when i start typing in the first textinput, i don't get the desired result. its only when i type in both that the evnet kicks in.
Reply | Threaded
Open this post in threaded view
|

Re: flex calculation problem

FlexCoders mailing list
It could be that unless both text inputs contain strings that parse into numbers you’ll get funky results like NaN for empty string.

From: "[hidden email]<mailto:[hidden email]> [flexcoders]" <[hidden email]<mailto:[hidden email]>>
Reply-To: "[hidden email]<mailto:[hidden email]>" <[hidden email]<mailto:[hidden email]>>
Date: Thursday, April 16, 2015 at 1:01 AM
To: "[hidden email]<mailto:[hidden email]>" <[hidden email]<mailto:[hidden email]>>
Subject: Re: [flexcoders] flex calculation problem



Hello, thanks for the response. i am already using a change listener on the text input but when i start typing in the first textinput, i don't get the desired result. its only when i type in both that the evnet kicks in.