(Variable addition) problem with AS.2

hi evey one…
i have littil problem with flash in the [COLOR=blue]addition[/COLOR] using the variables
Every thing is working normaly.
the [COLOR=#0000ff]subtraction[/COLOR] and the others are working fine
the only problem is the addition

when i teake the variable from Text feald or external source hte flash will add the numbers beside each other . it treat them as strings :td:
chick the attatchment to see what i mean

but when identfy the variable in the action befor the addition works normal:pleased:
like

 
nom1 = 5;
nom2 = 6;
trace (nom1+nom2); // output = 11

,
any one can help me in this ?

thanks first

on(release){
 _root.resultq = Math.round(Number(_root.nom1)+Number(_root.nom2));
}

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.

  1. 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.

  1. 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