Ultimate Gear War
Join the alien war, prepare your gear and protect your base at all cost!
4.15 / 5.00 16,792 ViewsXML is a very good and importent way to work with external data in flash, it's easy, implented and efficient to save levels, maps, and data in general. I will cover the basics of loading XML and processing it here.
First we learn XML
There really isn't much to learn about xml, there are no commands or anything, it's a way of storing data. we start with the type we're saving for example level, then we put the attributes followed by the data. for example here is what I used. remmember, every tag we open we close.
<level id='1' name="Forest of Home>
</level>
there , I created a new level, now let's pour some data in, there are 2 ways of storing data in xml, like this:
<data id=1 />
no need to close the tag, we gave it an attribute and it's one
and
<data>1</data>
this is the other way, I ususally preffer the first way, this tutorial isn't about teaching xml, so if you're interested in actual xml this is an excellent tutorial
opening an xml file
The first thing we need to do is open the xml file we're parsing, for this tutorial i'm using the following file
<data>
<Message text="Welcome to Godlimation" />
<Message text="Site Created By Inglor" />
<Message text="This site belongs to Patrick, creator of Xunmato" />
<Message text="Visit our new link section" />
<Message text="The user system, is N/A yet" />
<Message text="Mo likes to touch little kids" />
<Message text="David and Goliath, coming soon" />
</data>
this is an XML document I've created somewhat not too long ago for a site I'm working on, it's named "data.xml".
now let's open it in flash, the first thing we need to do is create a new XML handler object
this is done the following:
Messages=new XML();
I named it Messages, I could have picked any other name.
the second thing we must do is clear out all the white spaces, this is very importent since that way our data is clean and " "s in our XML are ignored.
this is done the following:
Messages.ignoreWhite = true;
the next thing we need to do is load the actual xml file into flash, this is done with the load command,
Messages.load('data.xml');
now we have an XML object handler with all the XML data inside it, all we have to do now is process it.
Parsing the XML
now messages has several "childs", these are the contents of him
Messages.onLoad = function(success) {
if (success) {
readMessages();
}
};
every time you open a XML file always include a onLoad function, this is what triggers when the XML loads
my read messages function is the following
Messages.onLoad = function(success) {
if (success) {
readMessages();
}
};
function readMessages(){
_root.a=new Array();
for(i=0;Messages.firstChild.childNodes[i]!=undefined;i++){
base=Messages.firstChild.childNodes[i].attributes.text;
trace(base);
_root.a.push(base);
}
_root.delay=0;
_root.onEnterFrame=function():Void{
if(_root.delay==0){
this.message=this.a[random(this.a.length)];
_root.delay=60;
}
_root.delay-=_root.delay>0;
}
}
I will explain the terms now
for(i=0;Messages.firstChild.childNodes[i]!=undefined;i++){
this runs untill the node of the first child (which are the <message> tags since they are nodes of the <data> tag) is undefined meaning, untill thre are no more messages to read.
base=Messages.firstChild.childNodes[i].attributes.text;
the firstChild is data, the child node is the current message, now attributes are the data, and text is the attribute I'm addressing (since it's text="blablabla" in the XML file)
trace(base);
_root.a.push(base);
and I trace it and push it into a data array, now after the loop ends I have all my data in the array and I'm free to process it ;)
Hope this tutorial contributed, I know it's kinda confusing, please ask any questions.
extendable markup language
this isn't very useful for scoreboards (SQL databases are better at that since you don't have to load data into flash but just send it.) but it is VERY GOOD AND VERY IMPORTENT at hight levels, for example, multiplayer games are done through XML sockets, and it's very good to load level maps using it, and it works great with php for loading and setting external live data. XML is quick too :)
At 6/30/05 11:25 AM, Dancing-Thunder wrote:At 6/30/05 11:21 AM, T-H wrote: I like it, I've heard about XML (external markup lang right?), but never learnt any. Would this be useful for making scoreboards?For scoreboards, I think you have to use PhP.
Or ASP. Both of the Overrun scoreboards are pulled from MS Access databases through ASP pages. Basically the same principle as MYSQL/PHP, just slightly different procedures and coding.
I have also never really touched upon XML, never really had the need to, but I think it's probably time to get to grips with it.
At 10/24/05 03:45 PM, -Toast- wrote:At 10/24/05 03:31 PM, Creeepy wrote:Lol, don't expect to be making a massive multiplayer game before years of experience :PAt 10/24/05 11:08 AM, Creeepy wrote: can u use XML to make massive multiplayer online games?*bump*
=D
=P no, i wasnt acctually hoping to get a finished script right in my hand!!
i was just wondering, cuz then i would maybe study on XML so i can be able to make this type of games in some years :)
At 10/24/05 03:45 PM, -Toast- wrote:At 10/24/05 03:31 PM, Creeepy wrote:Lol, don't expect to be making a massive multiplayer game before years of experience :PAt 10/24/05 11:08 AM, Creeepy wrote: can u use XML to make massive multiplayer online games?*bump*
=D
Dont expect to do that for years because flash is currently too shit
- Matt, Rustyarcade.com
At 10/24/05 05:08 PM, Ninja-Chicken wrote:At 10/24/05 03:45 PM, -Toast- wrote:
Lol, don't expect to be making a massive multiplayer game before years of experience :PDont expect to do that for years because flash is currently too shit
mhmm... wait a sec... isnt that what is coming???
shit have I said too much... or not enough?
At 10/24/05 05:45 PM, -KhAo- wrote:At 10/24/05 05:08 PM, Ninja-Chicken wrote:At 10/24/05 03:45 PM, -Toast- wrote:mhmm... wait a sec... isnt that what is coming???Lol, don't expect to be making a massive multiplayer game before years of experience :PDont expect to do that for years because flash is currently too shit
shit have I said too much... or not enough?
??? What
Dude your not going to be able to make a massivly multiplayer game because flash is too weak to handle it
- Matt, Rustyarcade.com
At 10/24/05 05:54 PM, -KhAo- wrote:At 10/24/05 05:47 PM, Ninja-Chicken wrote:??? Whatit could rip your head apart if only it wanted to!
Dude your not going to be able to make a massivly multiplayer game because flash is too weak to handle it
i think ive seen some flash-based MMORPGs...
snyggys
At 1/10/06 08:42 PM, Neashir wrote: Both of you noobs trying to get your post count up, fuck off. We don't need your spam.
Look who's spamming.
Nice XML tutorial Inglor :)
^to stay on topic^
wat
a compessor wil raise the volume while lowering the db - chronamut
Awesome tutorial. Although I'm still a little confused with parsing the XML with the childs, nodes, etc.
At 5/4/08 11:10 AM, adam2510 wrote: how do i Write to xml in flash without php?
Stop. Bumping. Old. Threads.
Just make a new topic. Also, XML isn't even necessary, it's just one way to send information to a server. On the other end I don't really know, but I'm pretty sure the tutorial explains it. Next time just make a new topic.
MY E-PENIS IS BIGGER THAN YOURS
8=================================>
...and this is my fag...
I have code exactly like the one you posted, but for some reason, whatever I try, Flash runs the function last, I used the debugger to find this. This means that I can't actually use what's I'm defining in an Array, which makes this all useless. What can I do?
Decima: The Last Story of Vald has a Facebook page and a development blog. Give them a look!
------------------------------