00:00
00:00

As: Xml 2005-06-30 11:18:29


AS: Main

XML 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.

Learn XML
the flash XML faq
Useful Resource
XML tutorials

Response to As: Xml 2005-06-30 11:21:56


I like it, I've heard about XML (external markup lang right?), but never learnt any. Would this be useful for making scoreboards?

Response to As: Xml 2005-06-30 11:25:40


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.

Response to As: Xml 2005-06-30 11:26:32


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 :)

Response to As: Xml 2005-06-30 12:19:42


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.


- - Flash - Music - Images - -

BBS Signature

Response to As: Xml 2005-06-30 12:21:58


yea, the thing is ASP servers ususally cost money where there are plenty MySQL+PHP free hosts ;)

but yea, nothing wrong with ASP and ASPX

XML is really useful, you should use it for your site ;) a bunch of cool stuff can be accomplished with it

Response to As: Xml 2005-10-24 11:08:39


can u use XML to make massive multiplayer online games?

Response to As: Xml 2005-10-24 15:31:53


At 10/24/05 11:08 AM, Creeepy wrote: can u use XML to make massive multiplayer online games?

*bump*

=D

Response to As: Xml 2005-10-24 15:45:18


At 10/24/05 03:31 PM, Creeepy wrote:
At 10/24/05 11:08 AM, Creeepy wrote: can u use XML to make massive multiplayer online games?
*bump*

=D

Lol, don't expect to be making a massive multiplayer game before years of experience :P


BBS Signature

Response to As: Xml 2005-10-24 15:49:34


At 10/24/05 03:45 PM, -Toast- wrote:
At 10/24/05 03:31 PM, Creeepy wrote:
At 10/24/05 11:08 AM, Creeepy wrote: can u use XML to make massive multiplayer online games?
*bump*

=D
Lol, don't expect to be making a massive multiplayer game before years of experience :P

=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 :)

Response to As: Xml 2005-10-24 17:08:15


At 10/24/05 03:45 PM, -Toast- wrote:
At 10/24/05 03:31 PM, Creeepy wrote:
At 10/24/05 11:08 AM, Creeepy wrote: can u use XML to make massive multiplayer online games?
*bump*

=D
Lol, don't expect to be making a massive multiplayer game before years of experience :P

Dont expect to do that for years because flash is currently too shit


- Matt, Rustyarcade.com

Response to As: Xml 2005-10-24 17:45:06


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 :P
Dont 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?

Response to As: Xml 2005-10-24 17:47:12


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:
Lol, don't expect to be making a massive multiplayer game before years of experience :P
Dont 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?

??? 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

Response to As: Xml 2005-10-24 17:54:41


At 10/24/05 05:47 PM, Ninja-Chicken wrote:
??? What
Dude your not going to be able to make a massivly multiplayer game because flash is too weak to handle it

it could rip your head apart if only it wanted to!

Response to As: Xml 2005-10-24 17:57:22


At 10/24/05 05:54 PM, -KhAo- wrote:
At 10/24/05 05:47 PM, Ninja-Chicken wrote:
??? What
Dude your not going to be able to make a massivly multiplayer game because flash is too weak to handle it
it could rip your head apart if only it wanted to!

i think ive seen some flash-based MMORPGs...


snyggys

Response to As: Xml 2005-10-24 18:03:47


At 10/24/05 05:57 PM, 2k_rammerizkool wrote:
i think ive seen some flash-based MMORPGs...

me too

Response to As: Xml 2005-11-18 17:47:24


Is there a way to spread XML nodes to AS variables? Like:

<stuff>
<this>Hi</this>
<that name="Something">Somethng Aweful</that>
</stuff>

would be:

this="Hi"
name="Something"
that="Something Aweful"

Response to As: Xml 2005-11-20 13:45:14


Does loading exernal XML files require that the .swf and the XML file is on the same domain?


BBS Signature

Response to As: Xml 2006-01-10 20:33:48


wow


BBS Signature

Response to As: Xml 2006-01-10 20:39:40


yes

Response to As: Xml 2006-01-10 20:42:10


At 11/20/05 01:45 PM, Claxor wrote: Does loading exernal XML files require that the .swf and the XML file is on the same domain?

no, go take a look at AS:Main and find the tutorial on cross-domain by Denvish

Response to As: Xml 2006-01-10 20:42:13


At 1/10/06 08:33 PM, invaderzig1 wrote: wow
At 1/10/06 08:39 PM, Hooked_ON_Phoneix wrote: yes

Both of you noobs trying to get your post count up, fuck off. We don't need your spam.

Response to As: Xml 2006-01-10 21:26:46


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

Response to As: Xml 2006-06-25 16:40:17


Cool. How would you go about creating and appending xml files in flash?


the events are merely fictional, written, directed, and acted out by all who create them

BBS Signature

Response to As: Xml 2006-06-25 17:15:40


Awesome tutorial. Although I'm still a little confused with parsing the XML with the childs, nodes, etc.

Response to As: Xml 2007-02-27 16:51:37


ive played mmorpgs in flash if im not mistaken (tactics arena online)

Response to As: Xml 2008-05-04 11:10:49


At 6/30/05 11:18 AM, Inglor wrote: Hope this tutorial contributed, I know it's kinda confusing, please ask any questions.

how do i Write to xml in flash without php?


Web Hosting: Free! Premium!

BBS Signature

Response to As: Xml 2008-05-04 11:15:06


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...

BBS Signature

Response to As: Xml 2008-05-04 11:23:33


At 5/4/08 11:10 AM, adam2510 wrote: how do i Write to xml in flash without php?

The programming forum devoted two thread pages explaining to you that you CAN'T. If you could then I would have long since overwritten your hard drive. Get the idea?


BBS Signature

Response to As: Xml 2008-07-14 07:46:36


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?


BBS Signature