I am trying to make a math equation in as2 for Flash. I want it so when someone enters a number into the input text box and presses the button, it adds up that number with another set number(5).
This is the code that I have for the stage.
var number2:Number = 5;
var number1:Number = parseInt(text_txt.text);
button_btn.onRelease = function()
trace(number1 + number2);
button_btn is the instance name button that I press.
text_txt is the instance name for the input text
In the output box is just says NaN(not a number). It doesn't matter what number I put in for the text box.
When I switch the parseInt(text_txt.text) with a number it works perfectly fine but in that way it doesn't use the input text box
Take in note that I am still very much a noob at Flash. I know very little about coding.
Thanks in advance for whoever can help.
When you assign the text value to the variable, it takes on whatever value the text has at that moment. It does not keep track of that variable and update as it changes.
Move the assignment of a value to number1 inside the button's function..
Thank you so much for the reply Ned, it worked.