A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [Help] Reading number values

  1. #1
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167

    [Help] Reading number values

    Hello everyone, forgive me for writing another thread, but as Im new to xml I have a quick question

    I have an xml file that contains a score <score1>100</score1> and all I want to do is compare it to a number that the user inputs into the input text box

    Im not asking how to go about loading the xml and all that jazz, I simply want to compare the two in an 'if statment"

    Here is what I had :

    currentScore = input.text;
    ...
    ...
    if (currentScore>highscore[0]) {
    display.text = "You are in FIRST place";
    } else if (currentScore>highscore[1] && currentScore<highscore[0]) {
    display.text = "You are in SECOND place";
    } else if (currentScore>highscore[2] && currentScore<highscore[1]) {
    display.text = "You are in THIRD place";
    } else {
    display.text = "You did NOT make the list";
    }


    The highscore array contains the top three xml nodes each containing a different number value

    But for some odd reason the two wont be compared and it always jumps to the final 'else' statment. I think this is because the input box is using Integer values whereas the xml file is using String

    Can someone please help me out, it would be greatly appreciated
    Last edited by Osteel; 10-31-2005 at 02:28 PM.

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518

    XML is fun :)

    Where ever you are reading in the highscore elements from the XML file, change the node to a 'string' and then change it to a 'number'.

    Code:
      highscore[i]  = Number(String(scoreElement[i].firstChild));
    And now this should work.
    Code:
    	if (currentScore>highscore[0]) {
    		//display.text = "You are in FIRST place";
    		trace("You are in FIRST place");
    	} else if (currentScore>highscore[1]) {
    		//display.text = "You are in SECOND place";
    		trace("You are in SECOND place");
    	} else if (currentScore>highscore[2]) {
    		//display.text = "You are in THIRD place";
    		trace("You are in THIRD place");
    	} else {
    		//display.text = "You did NOT make the list";
    		trace("You did NOT make the list");
    	}

  3. #3
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Great it works !

    Many thanks, on your reply

    Haha, now I know where to come with my (and yes there will be more) xml questions


    Well actually just too clarify, when Im putting a number back into the xml, do I have to convert it to a string?

    For example, when I tried:
    highscore[0].nodeValue = currentScore;

    It kept the same nodeValue as it was previoius that line of code
    Last edited by Osteel; 10-31-2005 at 05:58 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center