A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [Help] New person cant read node ...

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

    [Help] New person cant read node ...

    Hey everyone

    Well Im new to XML and Im trying to get a highscore system to work for a game Ive created. Im not asking you to make one for me, I just need a little help with this problem Im having

    For the sake of tutorial and learning, Ill just break it down to the specific problem that Im facing

    1) I have an XML file called 'highscore.xml' with the following in it:

    <?xml version="1.0"?>
    <highscore>
    <player1>Matthew</player1>
    <score1>100</score1>
    </highscore>

    2) I then load the xml into flash using:
    my_xml.load("C:\\Inetpub\\wwwroot\\games\\highscor e.xml");

    3) I attempt to grab the first node 'player' to simply display it in a trace (for now) :
    highElement = my_xml.firstChild;
    playerElement = highElement.firstChild;
    playerText = playerElement.nodeValue;
    trace(playerText);

    As you can see Ive made variables for the different parts of the xml all the way down to the text inside the element 'player'. When I run the program and click the button in which the code is in, the trace(playerText); returns an undefined value

    Here is my whole code for the button :

    on (release) {
    my_xml = new XML();
    myLoadxml = new XML();
    my_xml.load("C:\\Inetpub\\wwwroot\\games\\highscor e.xml");


    my_xml.onLoad = function(success) {
    if (success) {
    highElement = my_xml.firstChild;
    playerElement = highElement.firstChild;
    playerText = playerElement.nodeValue;
    trace(playerText);

    my_xml.contentType = "text/xml";
    my_xml.xmlDecl = "<?xml version=\"1.0\" ?>";
    my_xml.sendAndLoad("http://localhost/games/test.asp", myLoadxml);
    trace(my_xml.firstChild.nodeValue);
    } else {
    }
    };
    }


    If someone code please help me out with this XML, it would be greatly appreciated
    Last edited by Osteel; 10-31-2005 at 09:05 AM.

  2. #2
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Hm, for some odd reason it is not displaying the text thats inside the xml file, I dont know why..

    Either way, I hope you can figure it out ...

  3. #3
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Maybe try it this way...
    Code:
    on (release) {
    	my_xml = new XML();
    	my_xml.ignoreWhite=true;
    	myLoadxml = new XML();
    	my_xml.load("C:\\Inetpub\\wwwroot\\games\\highscore.xml");
    	my_xml.onLoad = function(success) {
    		if (success) {
    			highElement = my_xml.firstChild;
    			playerElement = highElement.firstChild.childNodes[0];
    			playerText = playerElement.nodeValue;
    			trace(my_xml);
    			trace(playerText);
    		};
    	};
    };
    Last edited by dawsonk; 10-31-2005 at 11:37 AM.

  4. #4
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Wow thanks alot, it works

    Ill try to figure out what does and what and hopefully Ill complete this highscore problem

    Many thanks

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