3 Replies Latest reply on Oct 1, 2012 10:32 AM by kglad

    My calculater program is outputting a letter ("a") rather than a number?

    Mrbo0m Level 1

      I have been making a simple calculation program to output a numerical value dependant on  the height and number of parts to an object.

       

      It works fine just multiplying the height but when I try to intergrate the part count the code doesn't work.

       

      There are no Errors just the SWF outputs the letter "a" rather than the anwser (Number).

       

      I think it is something to do with my String var type but im not sure, any help would be greatly appreciated.

       

      Here is my code:

       

      import flash.ui.Mouse;

       

      var Hnum:String;

      var PCnum:String;

      var PCcalc:Number;

      var Pmath:Number;

      var calc:Number = 25;

      var Total:Number;

       

      num1.restrict = "0-9";

      num2.restrict = "0-9";

       

      Est_btn.addEventListener(MouseEvent.CLICK, calculate);

      function PartCount(event:MouseEvent):void{

       

       

          if (parseInt(PCnum) > 0 && parseInt(PCnum)< 10){

              PCcalc == 1;

          }

         

          if (parseInt(PCnum) > 11 && parseInt(PCnum)< 20){

              PCcalc == 2;

          }

         

          if (parseInt(PCnum) > 21 && parseInt(PCnum)<200){

              PCcalc == 3;

          }

      }   

       

      Est_btn.addEventListener(MouseEvent.CLICK, calculate);

      function PartCalc(event:MouseEvent):void{

         

          if (PCcalc == 1){

              Pmath * 10;

          }

         

          if (PCcalc == 2){

              Pmath * 5;

          }

         

          if (PCcalc == 3){

              Pmath * 1;

          }

      }

       

       

      Est_btn.addEventListener(MouseEvent.CLICK, calculate);

      function calculate(event:MouseEvent):void{

         

          Hnum = num1.text;

          PCnum = num2.text;

          Total = parseInt(Hnum) * calc + Pmath;

          Total.toString();

          Total_txt.text = String(Total);

         

      }

       

      Thanks in advance.

       

      MrB.

        • 1. Re: My calculater program is outputting a letter ("a") rather than a number?
          kglad Adobe Community Professional & MVP

          1. you have 3 lines of code that are the same (your addEventListener code).

          2. you never call PartCalc and you never call PartCount

          3. even if you call PartCalc, it does nothing. in particular, it fails to define Pmath.

          4. Pmath is always NaN. you need to assign it a value.

          • 2. Re: My calculater program is outputting a letter ("a") rather than a number?
            Mrbo0m Level 1

            Thanks guys here is the working code.

             

             

            import flash.ui.Mouse;

             

            var Hnum:String;

            var PCnum:String;

            var PCcalc:Number ;

            var Pmath:Number = 0;

            var calc:Number = 25;

            var Total:Number;

             

            num1.restrict = "0-9";

            num2.restrict = "0-9";

             

            Est_btn.addEventListener(MouseEvent.CLICK, PartCount);

            function PartCount(event:MouseEvent):void{

               

                Hnum = num1.text;

                PCnum = num2.text;

             

             

                if (parseInt(PCnum) > 0 && parseInt(PCnum)< 10){

                    PCcalc = 1;

                }

               

                if (parseInt(PCnum) > 11 && parseInt(PCnum)< 20){

                    PCcalc = 2;

                }

               

                if (parseInt(PCnum) > 21 && parseInt(PCnum)<200){

                    PCcalc = 3;

                }

            }   

             

            Est_btn.addEventListener(MouseEvent.CLICK, PartCalc);

            function PartCalc(event:MouseEvent):void{

               

               

                if (PCcalc == 1){

                    Pmath = 10;

                }

               

                if (PCcalc == 2){

                    Pmath = 5;

                }

               

                if (PCcalc == 3){

                    Pmath = 1;

                }

            }

             

            Est_btn.addEventListener(MouseEvent.CLICK, calculate);

            function calculate(event:MouseEvent):void{

               

                Hnum = num1.text;

                PCnum = num2.text;

                Total = (parseInt(Hnum) * calc) + (parseInt(PCnum) * Pmath);

                Total.toString();

                Total_txt.text = String(Total);

               

            }