[flexcoders] flex calculation problem

4 views
Skip to first unread message

stinasius@yahoo.com [flexcoders]

unread,
Apr 15, 2015, 8:12:32 AM4/15/15
to flexc...@yahoogroups.com
 

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>



__._,_.___

Posted by: stin...@yahoo.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (1)

.

__,_._,___

stinasius@yahoo.com [flexcoders]

unread,
Apr 15, 2015, 9:49:32 AM4/15/15
to flexc...@yahoogroups.com
 

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))

.

__,_._,___

stinasius@yahoo.com [flexcoders]

unread,
Apr 15, 2015, 2:55:58 PM4/15/15
to flexc...@yahoogroups.com

Abhinay Dronamraju abhinay.dronamraju@yahoo.com [flexcoders]

unread,
Apr 15, 2015, 5:54:14 PM4/15/15
to flexc...@yahoogroups.com
 

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. 


Sent from my iPhone

__._,_.___

Posted by: Abhinay Dronamraju <abhinay.d...@yahoo.com>
.

__,_._,___

stinasius@yahoo.com [flexcoders]

unread,
Apr 16, 2015, 4:02:00 AM4/16/15
to flexc...@yahoogroups.com
 

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.

__._,_.___

Posted by: stin...@yahoo.com
.

__,_._,___

Alex Harui aharui@adobe.com [flexcoders]

unread,
Apr 17, 2015, 12:12:58 AM4/17/15
to flexc...@yahoogroups.com
 

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: "stin...@yahoo.com [flexcoders]" <flexc...@yahoogroups.com>
Reply-To: "flexc...@yahoogroups.com" <flexc...@yahoogroups.com>
Date: Thursday, April 16, 2015 at 1:01 AM
To: "flexc...@yahoogroups.com" <flexc...@yahoogroups.com>
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.

__._,_.___

Posted by: Alex Harui <aha...@adobe.com>
.

__,_._,___
Reply all
Reply to author
Forward
0 new messages