Skip to main content
Participant
May 1, 2007
Answered

Help: Casting String gotten from Xml to a Number Type

  • May 1, 2007
  • 2 replies
  • 437 views
Hi all,

I have a major problem, I have parsed the data from an xml doc to global vars in flash and need to use a few of them as numbers for things the position of "nodes" on the screen. However I can not cast the data stored as a var to a number or int value.

For example in the code below when the set Node button is pressed it traces the "Node's" current X value, then the value in the global var gotten from the xml, which contains the x position of where to place the Node.

Next it creates a new var of Number Type and assigns it the Number value of the string in global var.

It then traces the new value of SNtopLeftX and sets the x pos of the Node's movie clip to the value of SNtopLeftX

However the Node doesn't move and this is the output I get from the traces

Start Node is at x = -734.5
nod_topLeftX is 16
TopLeftX = 16
SN TopLeftX = NaN

I do not understand why I am getting NaN when the string of nod_topLefX is 16, any ides?
-------------------------------------------------------------------------------------------------------------------
This topic has been closed for replies.
Correct answer kevmann16
I've managed to gwet it working with help, I can force it to an integer using:
_global.nod_topLeftX = parseInt(xmlDoc_xml.firstChild.childNodes[3].childNodes[0].childNodes[3].childNodes[0]);

2 replies

kevmann16AuthorCorrect answer
Participant
May 1, 2007
I've managed to gwet it working with help, I can force it to an integer using:
_global.nod_topLeftX = parseInt(xmlDoc_xml.firstChild.childNodes[3].childNodes[0].childNodes[3].childNodes[0]);
Inspiring
May 1, 2007

Hi,

you got some casing mixed up:

nod_topLeftX
Number(nod_TopLeftX);

lower "t" one time, upper the other.

Manno

kevmann16 wrote:
> Hi all,
>
> I have a major problem, I have parsed the data from an xml doc to global vars
> in flash and need to use a few of them as numbers for things the position of
> "nodes" on the screen. However I can not cast the data stored as a var to a
> number or int value.
>
> For example in the code below when the set Node button is pressed it traces
> the "Node's" current X value, then the value in the global var gotten from the
> xml, which contains the x position of where to place the Node.
>
> Next it creates a new var of Number Type and assigns it the Number value of
> the string in global var.
>
> It then traces the new value of SNtopLeftX and sets the x pos of the Node's
> movie clip to the value of SNtopLeftX
>
> However the Node doesn't move and this is the output I get from the traces
>
> Start Node is at x = -734.5
> nod_topLeftX is 16
> TopLeftX = 16
> SN TopLeftX = NaN
>
> I do not understand why I am getting NaN when the string of nod_topLefX is 16,
> any ides?
>
> --------------------------------------------------------------------------------
> -----------------------------------
>
> butNodeSet.onRelease = function() {
>
> trace ("Start Node is at x = " + mcStartNode._x);
> trace ("nod_topLeftX is " + nod_topLeftX);
>
> var SNtopLeftX:Number = Number(nod_TopLeftX);
> trace ("StartNode TopLeftX = " + SNtopLeftX);
> mcStartNode._x = SNtopLeftX;
> }
>

--
----------
Manno Bult
http://www.aloft.nl
manno@xs4all.nl
kevmann16Author
Participant
May 1, 2007
Hi,

Thank you for your help but it made no difference. Even if I use the line:

_global.nod_topLeftX = Number(xmlDoc_xml.firstChild.childNodes[3].childNodes[0].childNodes[3].childNodes[0]);

So it selects the number value as I import it I get Is NaN if I trace nod_topLeftX