PDA

View Full Version : Flex calculator??


loki421
04-28-2009, 05:59 PM
Hi all,

I've been playing with a little app today, i came accross a simple tip calculator here http://blog.flexexamples.com/2007/09/17/building-a-simple-tip-calculator-in-flex/ and thought i'd have a go at building my own calculator.

What i've got is a radiobutton group that selects either "one" or "two", then a text input (which i'm struggling to convert to numbers, something to do with parseFloat i think), and a button to calculate. Basically i'm interested in what components can be used to preform calculations.

Here's the code so far:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

<mx:Script>
<![CDATA[

private function getTotal():void
{
total.text = <!--- radioGroup selection or value, +/-/* etc whatever the user types in the textinput --->
}

]]>
</mx:Script>



<mx:RadioButtonGroup id="radioGroup"/>
<mx:RadioButton label="1 - 4" groupName="radioGroup" value="one"/>
<mx:RadioButton label="5 - 8" groupName="radioGroup" value="two"/>
<mx:TextInput id="input"/>
<mx:TextInput id="total"/>
<mx:Button label="Button" click="getTotal();"/>

</mx:Application>


So that's basically just the components ready for the logic, but i'm really stumped now as to where to go with this.

Would anybody like to help with this?

Any pointers or links to tutorials would be gratefully recieved as always :D

Looking forward to your ideas all!!!! :)

loki421
04-28-2009, 06:57 PM
Ha! Check me out.... i've manged to work it out all on my tod :p lol

Here's the solution for anyone else who wants to have a play :D


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

<mx:Script>
<![CDATA[

private function getTotal():void
{
var myInt:int = parseInt(input.text);
var myFloat:Number = parseFloat(input.text);
var myNumber:Number = new Number(input.text);

total.data = (myNumber - 1) + (radioGroup.selectedValue);
}

]]>
</mx:Script>



<mx:RadioButtonGroup id="radioGroup"/>
<mx:RadioButton label="1 - 4" groupName="radioGroup" value="3.50"/>
<mx:RadioButton label="5 - 8" groupName="radioGroup" value="5.25"/>
<mx:TextInput id="input" restrict="0-9" />
<mx:TextInput id="total"/>
<mx:Button label="Button" click="getTotal();"/>

</mx:Application>


Hope this helps someone :)