Be a Supporter!

As: Xml

  • 5,851 Views
  • 53 Replies
New Topic Respond to this Topic
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
As: Xml 2005-06-30 11:18:29 Reply

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

T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to As: Xml 2005-06-30 11:21:56 Reply

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

Dancing-Thunder
Dancing-Thunder
  • Member since: Apr. 19, 2005
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to As: Xml 2005-06-30 11:25:40 Reply

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.

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to As: Xml 2005-06-30 11:26:32 Reply

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

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to As: Xml 2005-06-30 12:19:42 Reply

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
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to As: Xml 2005-06-30 12:21:58 Reply

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

Creepy
Creepy
  • Member since: Nov. 28, 2004
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to As: Xml 2005-10-24 11:08:39 Reply

can u use XML to make massive multiplayer online games?

Creepy
Creepy
  • Member since: Nov. 28, 2004
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to As: Xml 2005-10-24 15:31:53 Reply

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

*bump*

=D

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to As: Xml 2005-10-24 15:45:18 Reply

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
Creepy
Creepy
  • Member since: Nov. 28, 2004
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to As: Xml 2005-10-24 15:49:34 Reply

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

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to As: Xml 2005-10-24 17:08:15 Reply

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

Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As: Xml 2005-10-24 17:45:06 Reply

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?
Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to As: Xml 2005-10-24 17:47:12 Reply

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

Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As: Xml 2005-10-24 17:54:41 Reply

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!

Rammer
Rammer
  • Member since: Jun. 8, 2003
  • Offline.
Forum Stats
Member
Level 33
Programmer
Response to As: Xml 2005-10-24 17:57:22 Reply

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

Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As: Xml 2005-10-24 18:03:47 Reply

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

me too

Fire
Fire
  • Member since: Oct. 29, 2003
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to As: Xml 2005-11-18 17:47:24 Reply

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"

Claxor
Claxor
  • Member since: Oct. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As: Xml 2005-11-20 13:45:14 Reply

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


BBS Signature
Ptcfast
Ptcfast
  • Member since: Jan. 7, 2006
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to As: Xml 2006-01-10 20:33:48 Reply

wow


BBS Signature
Hooked-ON-Phoneix
Hooked-ON-Phoneix
  • Member since: Jan. 2, 2006
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to As: Xml 2006-01-10 20:39:40 Reply

yes

Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As: Xml 2006-01-10 20:42:10 Reply

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

Neashir
Neashir
  • Member since: Aug. 8, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to As: Xml 2006-01-10 20:42:13 Reply

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.

Thomas
Thomas
  • Member since: Feb. 14, 2005
  • Offline.
Forum Stats
Member
Level 13
Musician
Response to As: Xml 2006-01-10 21:26:46 Reply

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

Starogre
Starogre
  • Member since: May. 8, 2004
  • Offline.
Forum Stats
Member
Level 18
Artist
Response to As: Xml 2006-06-25 16:40:17 Reply

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
mynamewontfitin
mynamewontfitin
  • Member since: Sep. 1, 2003
  • Offline.
Forum Stats
Member
Level 19
Blank Slate
Response to As: Xml 2006-06-25 17:15:40 Reply

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

suppi
suppi
  • Member since: Jun. 29, 2003
  • Offline.
Forum Stats
Member
Level 07
Audiophile
Response to As: Xml 2007-02-27 16:51:37 Reply

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

adam2510
adam2510
  • Member since: Oct. 2, 2005
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to As: Xml 2008-05-04 11:10:49 Reply

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
El-Presidente
El-Presidente
  • Member since: Jun. 2, 2005
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to As: Xml 2008-05-04 11:15:06 Reply

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
GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to As: Xml 2008-05-04 11:23:33 Reply

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
Hoeloe
Hoeloe
  • Member since: Apr. 29, 2004
  • Offline.
Forum Stats
Member
Level 37
Game Developer
Response to As: Xml 2008-07-14 07:46:36 Reply

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?


Song of the Firefly is on Steam Greenlight and Kickstarter. Give them a look and support the project!
------------------------------

BBS Signature