A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: xml written check

  1. #1
    Junior Member
    Join Date
    May 2003
    Posts
    24

    xml written check

    Hi,

    I've made a game that writes highscore to XML file. First it reads existing XML file with scores and than compare current game score with existing scores in the XML file and than it rewrittes higher scores and adds new score to XML object and rewrites existing XML file with new one (with help of PHP ofcourse). The problem is that sometimes the server needs some time to write the new xml file and if I play the game again in meantime and get to scores, and if PHP hasn't finish writting new XML the game will load old XML so it will not show last score made.

    How to check if PHP has finished writting new XML file and tell flash to somehow wait for XML file to be rewritten?

    I hope I was clear, please help me, this is driving me crazy.
    Tnx

  2. #2
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    There might be many way to do this.

    Here are my first way:

    Put an Boolean Attribute in your xml structure. For example:

    PHP Code:
    <gameScore loaded="true">1780</gameScore
    When PHP loads the xml file into flash it checks the attribute and also re-write the xml attribute loaded to false.

    This will again re-write to true when the highest score will written. In the mean time if you start the game flash will check the loaded is true or not. If it loads false then flash will not allow to start the game.


    Simple...


    arkitx
    Last edited by arkitx; 04-29-2011 at 02:08 PM.

  3. #3
    Junior Member
    Join Date
    May 2003
    Posts
    24
    Thanks

    Could you explain this little more cause I still can't figure it out. What this 1780 value mean?

  4. #4
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    ActionScript Code:
    var bool:String;
    var score:XML = new XML();
    score.ignoreWhite = true;
    score.onLoad = function(success:Boolean) {
        if (success) {
            var xml = score.firstChild;
            bool = (xml.attributes.loaded);
            trace(xml.childNodes);
        } else {
            trace("unable to load XML");
        }
    };
    score.load("score.xml");

    start.onRelease = function() {
        trace(bool);
        if (bool == "true") {
            gameStart();
            bool = "false";
        }
        trace(bool);
    };

  5. #5
    Junior Member
    Join Date
    May 2003
    Posts
    24
    Thank you very much for the code.

    I've managed to solve it differently,

    I've added id attribute to XML <scores id="0"> which is changed by actionscript (generated random game id number) every time someone makes high score. Then flash checks in intervals if XML loaded has that number (checks if new XML file has been written to server). Then if current game id is the same as attribute in XML it means the XML file was saved. Then it enables "play game" button

  6. #6
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    Thank You,

    I was not able to see what I was posting until the moderator approved the post. This might be the policy of this forum, someone could not allowed under 10 posts.

    I was did that in some other way. If you need that I can post it.


    arkitx

  7. #7
    Junior Member
    Join Date
    May 2003
    Posts
    24
    Yes thank you, I would like to see how you done it
    Please post the code.
    Thanx

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