Hi!
I’m learning too, and this is what i’ve picked up from the text book.
Input box returns entered datum as “string”. To ensure that it is numbers we want, there are two steps involved that have worked well for me.
- When creating the input box, you will see a button in the Properties called Character…
Click on that and select the “Specify Ranges” option in the radio-checkboxes.
Then the options in the frame below become alive - select Numerals[0…9] in that.
- after that, in the AS code, use Number() to cast that datum as a number datatype.
(I have MX 2004, so I could not open your .fla)
Number(inputboxVariableName) - where inputboxVariableName is the name you gave in the “Var” field (not the instance name)in the Properties dialogue box for that input text box.
The Flash Interpreter tries to Automatically “type” data along expected lines depending upon the syntax. -, * and / operators involve automatic type conversion to number. In case a string is encountered that does not contain any numeral, for eg. “coffee”, it will convert it to a number type datum called NaN.
With “+” operator, there is a difference - it performs a concatenation operation instead when it encounters string datatype so trace(nom1 + nom2) is interpreted as “5” + “6” is converted to 56 instead of 11. The + operator does not automatically convert datatype unlike he other mathematical operators since it is also use for string concatenation.
You can always check your datatype by using typeof -
try this:-
trace(typeof nom1), before the two steps I suggested and again after the two steps I suggested.
The Number() method converts different datatypes to number.
Converting to a Number:-
Original Data -------Result After Conversion
undefined ----- 0
null --------- 0
Boolean ---------- 1 if original value is true, 0 if false
Numeric string --------Equivalent numeric value if string is
composed only of base-10 numbers
whitespace,exponent,decimal plus sign or minussign.
Other strings-------- NaN
"Infinity" ---------Infinity
"-Infinity" -------- -Infinity
"NaN" --------- NaN
Array-------------- NaN
Object -------------The return value of the Object’s valueOf() method
MovieClip-------------- NaN
This is from Moock’s guide.
Hope it helps.
s