I'm pretty new around here, and I've recently bought a book about flash game programming with Actionscript 1.0.
Let me be clear: No threads on this website or others have an answer to my question.
I know you guys have gotten many questions about the "parseInt" function used in Javascript, however none of them provide me with an answer.
I'm doing one of the excercises which involves creating an adder program, the user inputs two numbers and the program adds them together. My code looks like this:
btnAdd.onRelease = function() { sum = parseInt(A) + parseInt(B) }
This is an incredibly simple program which is infuriatingly refusing to work. Every time I test it, the output is NaN. Without fail.
A and B are referring the variables which I assigned to the Input text boxes. "sum" is referring to the variable which I assigned to the text box that displays the Output (Dynamic).
No, my variables are not wrong, I have probably sextuple checked them. The button instance name is correct too.
In my research to find an answer to this stupidly easy question, I've found these places: Research 1 Research 2
The first website has someone with the exact same question, however it was never answered and the one guy who did only suggested alternative coding which also returned "NaN".
There are also many other unrelated sites on stackoverflow that are discussing parseInt in different situations.
The only things I have actually learned from these places is that parseInt only returns NaN if it can't parse the string to an integer i.e. "fsd" would return "NaN" but "4" should return "4".
I enter only integers every time but it always gives me NaN.
I also tested the program without the parseInt like so:
btnAdd.onRelease = function() { sum = A + B }
I know this works perfectly because the output shows the two numbers next to each other (1 + 2 becomes 12, 4 + 6 becomes 46 etc.)
This is obviously due to flash thinking that the numbers are strings, when I really want them to be integers. That's what the parseInt is supposed to do.
What's happening? If you need pictures or any more info let me know.