Skip to main content
Known Participant
Nov 29, 2009 4:13 PM UTC
Question

Cannot load XML

I dont know much about Parsing XML with AS2. Any idea why this doesnt work? "Game can now be started", "In loadXML function" is traced. Unfortunately, "failed to load" is traced too. I put my cards.xml file in the same file as my main.asc.

===============================================================

Server side (main.asc)

===============================================================

application.onConnect = function(clientObj){
    application.acceptConnection(clientObj);
    clientObj._uniqueUserID = this.userID;
    this.userID++;
   
    if(this.userID == 2)
    {
        trace("Game can now be started");
        for (i = 0; i < application.clients.length; i++){
            application.clients.call("startGame");
        }
    }
   
    clientObj.loadXML= function(){
            var cardData = new XML();
            cardData.load("http://localhost/myapplication2/cards.xml");
            trace("In loadXML function");
            cardData.ignoreWhite = true;
            cardData.onLoad = function(success){
                if(success)
                {
                    trace("xml loaded");
                }
                else
                {
                    trace("failed to load");
                }
            }
        }
}

====================================================

Client side

====================================================

function startGame():void
{
    nc.call ("loadXML", null);

}

    This topic is closed to new replies. Start a new post to keep the conversation going.

    3 replies

    calmchessplayer
    Inspiring
    Nov 29, 2009 9:10 PM UTC

    This ("http://localhost/myapplication2/cards.xml");
                 is an address on a webserver where as the application folder containing the main.asc is local host...you either need to put the xml on a webserver or try to load the xml file using this ("cards.xml");


    Translate
    Known Participant
    Nov 30, 2009 3:49 AM UTC

    you're right, I have to upload the xml into some webserver and get that url, but I can't seem to test it locally, cardData.load("cards.xml"); doesn't seem to work either, even if I copy the whole directory ("C:/User/.........cards.xml");

    Any ideas how to test it locally?

    Translate
    Dec 1, 2009 3:36 PM UTC

    If you want to read an XML file in the application folder, use the File() class to read the contents of the XML file into a string, and then use the XML() class to parse that string into XML.

    Also, if the XML data is the same for all clients, you'd be better off just loading it once in your onAppStart handler, rather than loading it each time a client calls for it.

    Translate