Skip navigation
Mrbo0m
Currently Being Moderated

Flash rookie needs help with error messages when making simple calculator in AS3.

Sep 7, 2012 6:13 AM

Tags: #error #as3 #action_script_3 #string #variable #cs6 #calculator #rookie #error_messages #help_needed

I am trying to make a simple calculator I have been following this guide:

 

http://www.youtube.com/watch?v=5k3h37YKZJI

 

this is my code.

 

var Hnum:String;

var PCnum:String;

var calc:Number = 25;

var Total:String;

 

num1.restrict = "0-9";

num2.restrict = "0-9";

 

Est_btn.addEventListener(MouseEvent.CLICK, calculate);

function calculate(event:MouseEvent):void{

   

    Hnum = num1.txt;

    PCnum = num2.txt;

    Total = parseInt(Hnum) * calc;

    Total.toString();

    Total_txt.text = String(Total);

}

 

I am getting these 3 errors:

 

Scene 1, Layer 'Actions', Frame 1, Line 141067: Implicit coercion of a value of type flash.text:TextField to an unrelated type String.

 

Scene 1, Layer 'Actions', Frame 1, Line 151067: Implicit coercion of a value of type flash.text:TextField to an unrelated type String.

 

Scene 1, Layer 'Actions', Frame 1, Line 161067: Implicit coercion of a value of type Number to an unrelated type String.

 

 

I have two input text boxs named num1 and num2 and then one dynamic text box named Total_txt.

 

This should be so simple I really don't know what im doing wrong?

 

Any help would be really appreciated.

 

MrB

 
Replies
  • Currently Being Moderated
    Sep 7, 2012 7:13 AM   in reply to Mrbo0m

    If you look at the tutorial I think you will see that you are using "txt"  where "text" is required.  "text" is a property of a textfield, identifying the text that the textfield holds.  I don't know if you are doing something where the num1 object contains another object named txt, but I think my first sentence catches the problem.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 7, 2012 8:58 AM   in reply to Mrbo0m

    You're welcome

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points