2 Replies Latest reply on Mar 10, 2011 12:22 PM by ninjatogo

    Simple math problems


      I am having trouble with an app I'm trying to develop. Problem is that I have created many text boxes, some will be used for input of integers (no decimal) and the others will be used for numbers with decimals.


      What I want to do is,

      change the text on a label

            that displays the value of the numbers in the two text boxes (decimal and non-decimal)

                 multiplied together

                     and added to another set of similar numbers.


      How do I do this?


      I am pretty new to programming in general, any help appreciated.

        • 1. Re: Simple math problems

          In flex Number represents decimal, and int represent integers so while getting the TextInput.text typecast those to required once.


          var x:int = int(tiInteger.text);    //this is integer


          var y:Number = Number(tiNumber.text);


          var z:Number = x * y;


          I created a small demo let me know if you struck.


          <?xml version="1.0" encoding="utf-8"?>
          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                         xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">


                      protected function tiNumber_clickHandler(event:MouseEvent):void
                          tiNumber.text ="";
                      protected function tiInteger_clickHandler(event:MouseEvent):void
                          tiInteger.text ="";


                      protected function button1_clickHandler(event:MouseEvent):void
                          var x:Number=Number(tiNumber.text);
                          var y:int  = int(tiInteger.text);
                          var z:Number = x* y;
                          textLabel.text = String(z);




                  <!-- Place non-visual elements (e.g., services, value objects) here -->


              <mx:TextInput id="tiNumber" text="Number" click="tiNumber_clickHandler(event)" x="40" y="33"/>
              <mx:TextInput id="tiInteger" text="Integer" click="tiInteger_clickHandler(event)" x="323" y="32"/>
              <mx:Button click="button1_clickHandler(event)" label="multiply" x="214" y="113"/>
              <mx:Text id="textLabel"/>

          1 person found this helpful
          • 2. Re: Simple math problems
            ninjatogo Level 1

            Thanks alot, really appreciate the help!

            Just to let you in on what I'm making, it's a wish list calculator for the Blackberry Playbook.