Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts

    Flex calculator??

    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...lator-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:
    Code:
    <?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

    Looking forward to your ideas all!!!!
    Last edited by loki421; 04-28-2009 at 06:03 PM.

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts
    Ha! Check me out.... i've manged to work it out all on my tod lol

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

    Code:
    <?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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •