read/write XML-file

21 views
Skip to first unread message

Lemur Motion

unread,
Nov 13, 2015, 1:13:32 PM11/13/15
to HaxeFlixel
I'm creating a html5-game and I want to have a scoreboard on the site where everybody that plays the game can view who's got the highest score. Hence I want to access the score data from my html outside of the game. 

I'm thinking that the easiest way should be to read/write the highscores to a xml-file. 

I just cant figure out how to do this in haxeflixel. Does anybody have an idea? Is it even possible?

Lemur Motion

unread,
Nov 13, 2015, 3:33:56 PM11/13/15
to HaxeFlixel
I have found a soulution to my first problem - loading the xml-data. Still need to find out how to overwrite it with new data though.

Here's how my xml-file looks like:
<?xml version="1.0" encoding="utf-8" ?>
<data>

<score1>123</score1>
<score2>456</score2>
<score3>789</score3>
</data>

And this is my haxe code:
import openfl.net.URLLoader;
import openfl.net.URLRequest;
import openfl.events.Event;
import haxe.xml.Fast;
import Std;

class MenuState extends FlxState
{
private var score01:Int;
private var score02:Int;
private var score03:Int;

override public function create():Void
{
super.create();
var xmlloader:URLLoader = new URLLoader();
xmlloader.load(new URLRequest("assets/data/score.xml"));
xmlloader.addEventListener(Event.COMPLETE, _onxmlloaded);
}
private function _onxmlloaded(e:Event):Void
{
var scoreXML:Xml = Xml.parse("" + e.target.data);
var fast = new haxe.xml.Fast(scoreXML.firstElement());
score01 = Std.parseInt(fast.node.score1.innerData);
trace(score01);
score02 = Std.parseInt(fast.node.score2.innerData);
trace(score02);
score03 = Std.parseInt(fast.node.score3.innerData);
trace(score03);

}



Reply all
Reply to author
Forward
0 new messages