A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: saving high scores

Hybrid View

  1. #1
    Junior Member
    Join Date
    Jun 2004
    Posts
    3

    saving high scores

    ok, so here's my situation: i need to record the high scores in this online card game i have developed. as long as i can somehow send the user's high score(s) to this guy's remote server, i am all set. and also, to distinguish one user's scores from another's, i will need to retrieve the username at the start of the game. as of right now i have the score and username (whatever that will be) converted into an XML tag.from there, i have been following the tutorial/explanation in "Flash Help" but i am not sure how to know whether or not it works. see this:

    onClipEvent(load){
    //--------------------- create XML object
    scoreXML = new XML();
    scoreElement = scoreXML.createElement("SCORE");
    scoreElement.attributes.username = "JARED";//_root.userName;
    scoreElement.attributes.score = _root.totalScore;
    scoreXML.appendChild(scoreElement);
    trace(scoreXML);
    //Construct an XML object to hold the server's reply
    sentReplyXML = new XML();
    sentReplyXML.onLoad = _root.serverReply;
    //trace(sentReplyXML.onLoad);
    //Send SCORE element to the server, place the reply in sentReplyXML
    scoreXML.sendAndLoad([server name - censored], sentReplyXML);
    }

    when i run it within flash it tells me there is an error opening the page. all the code seems to work, but i just cant connect wth the server. is there something i am missing? or is there a better way to do it?

  2. #2
    Ihoss
    Guest
    If you want a simple highscore system, then try mine (in my footer). I'm not all into XML and stuff, but I think you need a file that can write to the server.

  3. #3
    Senior Member
    Join Date
    Feb 2002
    Posts
    147
    Flash has some issues using 'sendAndLoad' if the SWF and the target URL are not on the same domain, which sounds to be the case for you. Put an ASP or PHP on your server just to make sure that the problem is with cross-domain access. If that is indeed your problem, you'll probably need to work your way through this pretty little document, and create a cross-domain policy xml file:

    http://livedocs.macromedia.com/flash...e=12_as806.htm

    oops, an edit: the document I meant to link to is the 'allowing cross-domain data loading' one; there's a link to it on this one. For some reason their URLs seem to be the same, so I can't link directly to it.
    Last edited by octothorp; 06-29-2004 at 04:38 PM.

  4. #4
    Junior Member
    Join Date
    Jun 2004
    Posts
    3
    thanks. i'll give this a look see.

  5. #5
    Junior Member
    Join Date
    Jun 2004
    Posts
    3
    well ok, i am still confused about what i should do here. what files would need to be on the server? assume that i am working in the same domain (i think thats how the application will end up), at my ftp i have the swf and the html, is there anything else (php or xml) that needs to be there as well? should i have a default xml file for the swf to read, at least maybe to see if i can read from it? i am not really sure how i will know if the server accepts it... i am thinking that i need something on the server end to handle what happens when the swf tries to get a hold of it. sound right? if so, what kind of a file is that?

  6. #6
    Senior Member
    Join Date
    Feb 2002
    Posts
    147
    Here are the parts you need:

    -SWF file
    -simple XML file (to start with, just a single node, named 'high-scores' or something).
    -A PHP or ASP file. What works with your server? I really don't know much PHP, so I couldn't help you with your actual code unless you're using ASP. Either way, here's what your code needs to do:

    Create a new XML object using the file on the server.
    Create a new XML object using the posted data from the Flash file.
    --optional: check and see if the score is good enough to make the list
    Append the new node to the main node in the first Flash file.
    Save the XML file to the server.
    --optional:
    Sort the top ten high scores
    Write them as output (this will then be taken by Flash--the 'load' part of send and load). Back in Flash, you can then interpret and display them.

    You might want to post this question in the XML forum here on Flashkit--someone there would definitely be able to hook you up!

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