Groups | Blog | Home
all groups > flash actionscript > september 2004 >

flash actionscript : Is this a dumb bug? (about variable types)


jigen3
9/5/2004 6:01:08 PM
hello, i have a variable declared as:

_root.var = 2300;

when i do this:

_root.var += 100;
trace("_root.var: "+_root.var);

i get _root.var: 2300100;

is there something i am doing wrong or a workaround for what i really want to
do, which is to treat _root.var as a number, not a string.

thx
jigen3
_jrh_
9/5/2004 6:05:25 PM
Yes, _root.var is a string. To make it a number, do this:

_root.var = 2300;
_root.var = Number(_root.var);
_root.var += 100;
jigen3
9/5/2004 6:13:19 PM
ok thanks a lot, i'll do that...but i have been using other variables declared
and treated the same way and flash has been treating them as numbers...i didn't
start doing anything special i don't think...

anyway, thx again
_jrh_
9/5/2004 6:14:47 PM
If you get a chance, read O'Reilly's Actionscript for Flash MX:The definitive
Guide chapter 3 for much more information. Ther'es a bunch of rules I think
they fixed with the new declaration in MX 2004.
rlc5611
9/5/2004 6:38:57 PM
from the flash help file

+= (addition assignment)
Availability
Flash Player 4.
Usage
expression1 += expression2
Parameters
expression1,expression2 A number or string.

_root.var1 = 2300;
_root.var1 += 100;
trace(_root.var1); //returns 2400

(_root.var is not allowed in MX 2004 as var is a reserved word)



jigen3
9/5/2004 6:58:38 PM
ok thanks, (the actual var name isn't var...)

i think i found the problem...i'm using an xml file and did something like
this before it reached the point where i encountered the "+=" problem:

_root.var1 =
CityInfo_xml.firstChild.childNodes[3].childNodes[4].firstChild.nextSibling.first
Child.nodeValue;

where the nodevalue at that point in the xml file is a number...i just didn't
know it would be treated as a string...
Peo
9/7/2004 11:58:42 AM
[quoted text, click to view]

i belive that all externally loaded data is initially treated as if it is of
type String.
This goes for data loaded via loadVars and loadXML enyway, not sure about
other methods.

Peo

AddThis Social Bookmark Button