Groups | Blog | Home
all groups > flash actionscript > march 2006 >

flash actionscript : can't do comparison test between string and xml text data


sciweb$$$
3/2/2006 9:51:21 PM
Hello,
The following test does not work. The nodeType for the data is 3 (text), and
the values are returned as a 0 or 1, yet I can't do a simple test on that. Any
ideas anyone? I think it is some sort of data type mismatch between xml and
strings in Actionscript.

if (this.firstChild.childNodes.nodeName == "values") {
the_values=this.firstChild.childNodes;
if (the_values.childNodes.childNodes.nodeName=="dt_spsd"){

isvalidit=
the_values.childNodes.childNodes.nextSibling.nextSibling.firstChild.nodeValue;
isvalid = isvalidit;

if (testval == "0") {
temp_time = "stand by...";
temp_corr = "stand by...";

} else {
temp_time = the_values.childNodes.childNodes.firstChild;
temp_corr = the_values.childNodes.childNodes.nextSibling.firstChild;

}



}
FlashTastic
3/3/2006 5:03:26 PM
Try casting isvalid to a String.

if(String(isvalid) == "0"){
//your stuff here..
}else{
//your other stuff..
}

Cheers,
sciweb$$$
3/3/2006 5:13:11 PM
Unfortunately, that doesn't work. If I change the comparison to != instead of
== I get the message "stand by..." (so the if comparison is taking place - that
much is clear), but not when the condition should be satisfied when isvalid is
zero.

I also tried creating a variable called
var mytest:String;

and setting
mytest = String(isvalid);

then doing the comparison
mytest == "0"
but the results are unchanged.
FlashTastic
3/3/2006 7:33:56 PM
So when you trace isvalid, what value show up in the output window?

Cheers,
sciweb$$$
3/3/2006 7:42:07 PM
Thanks FlashTastic, I appreciate your interest. I moved the discussion over to
the Flash Data Integration area as I thought that might be more appropriate.

If I do trace isvalid, I get 0 back. If I do typeof(isvalid) I get String
back. I set the xml to type string this morning by setting
mydataXML.toString(); when loading the xml file, to solve any type issues.
FlashTastic
3/3/2006 7:49:06 PM
Casting a String to Boolean always returns true.

Have you tried casting it to a Number?

if(Number(isvalid) == 0){
//etc.
}

Cheers,
sciweb$$$
3/3/2006 7:51:47 PM
sciweb$$$
3/3/2006 7:58:32 PM
You nailed it!

Num won't cast it, but parseInt will:

if(parseInt(isvalid) == 0)

FlashTastic
3/3/2006 8:05:40 PM
Beer over the internet... mmm... *drool*.
I'm still at work, it's not nice to make a man salivate on Friday afternoon.

Glad you got it all figured out.

Cheers,
FlashTastic
sciweb$$$
3/3/2006 8:06:50 PM
AddThis Social Bookmark Button